File: test_example_raises.py

package info (click to toggle)
pytest-check 2.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 480 kB
  • sloc: python: 2,220; sh: 17; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 872 bytes parent folder | download
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
from pytest_check import check, raises


def test_raises_top_level_fail():
    with raises(AssertionError):
        x = 3
        assert 1 < x < 4


def test_raises_top_level_pass():
    with raises(AssertionError):
        x = 4
        assert 1 < x < 3


def test_raises_check_level_fail():
    with check.raises(AssertionError):
        x = 3
        assert 1 < x < 4


def test_raises_check_level_pass():
    with check.raises(AssertionError):
        x = 4
        assert 1 < x < 3


def test_raises_exception_value():
    with check.raises(ValueError) as e:
        raise ValueError("This is a ValueError")

    check.equal(str(e.value), "This is a ValueError")

def test_raises_msg_fail():
    """Should Fail, and the custom message should be in the output."""
    with check.raises(ValueError, msg="Custom error message"):
        x = 1 / 0 
        assert x == 0