File: test_raises.py

package info (click to toggle)
pytest-relaxed 2.0.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 212 kB
  • sloc: python: 960; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pytest

from pytest_relaxed import raises


class Boom(Exception):
    pass


class OtherBoom(Exception):
    pass


class Test_raises:
    def test_when_given_exception_raised_no_problem(self):
        @raises(Boom)
        def kaboom():
            raise Boom

        kaboom()
        # If we got here, we're good...

    def test_when_given_exception_not_raised_it_raises_Exception(self):
        # TODO: maybe raise a custom exception later? HEH.
        @raises(Boom)
        def kaboom():
            pass

        # Buffalo buffalo
        with pytest.raises(Exception) as exc:
            kaboom()
        assert "Did not receive expected Boom!" in str(exc.value)

    def test_when_some_other_exception_raised_it_is_untouched(self):
        @raises(Boom)
        def kaboom():
            raise OtherBoom("sup")

        # Buffalo buffalo
        with pytest.raises(OtherBoom) as exc:
            kaboom()
        assert "sup" == str(exc.value)