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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
def test_xfail(pytester):
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest("test_example_xfail.py::test_xfail")
result.assert_outcomes(xfailed=1)
result.stdout.fnmatch_lines(["* 1 xfailed *"])
def test_xfail_strict(pytester):
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest("test_example_xfail.py::test_xfail_strict")
result.assert_outcomes(xfailed=1)
result.stdout.fnmatch_lines(["* 1 xfailed *"])
def test_xpass(pytester):
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest("test_example_xfail.py::test_xfail_pass")
result.assert_outcomes(xpassed=1)
result.stdout.fnmatch_lines(["* 1 xpassed *"])
def test_xpass_strict(pytester):
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest("test_example_xfail.py::test_xfail_pass_strict")
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines(["* 1 failed *"])
def test_xfail_runxfail(pytester):
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest("--runxfail", "test_example_xfail.py")
result.assert_outcomes(passed=2, failed=9)
result.stdout.fnmatch_lines(["* 9 failed, 2 passed *"])
def test_xfail_raises_should_fail_check(pytester):
"""Test that xfail with raises should fail when wrong exception type in check"""
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest(
"test_example_xfail.py::test_xfail_raises_should_fail_check"
)
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines(["* 1 failed *"])
def test_xfail_raises_check_multiple_unmatched_marks(pytester):
"""Test that xfail with multiple unmatched raises should fail"""
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest(
"test_example_xfail.py::test_xfail_raises_check_multiple_unmatched_marks"
)
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines(["* 1 failed *"])
def test_xfail_raises_should_fail_check_tuple_single_value(pytester):
"""Test that xfail with tuple of single unmatched exception should fail"""
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest(
"test_example_xfail.py::test_xfail_raises_should_fail_check_tuple_single_value"
)
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines(["* 1 failed *"])
def test_xfail_no_raises_with_check(pytester):
"""Test backward compatibility: xfail without raises should still work with checks"""
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest(
"test_example_xfail.py::test_xfail_no_raises_with_check"
)
result.assert_outcomes(xfailed=1)
result.stdout.fnmatch_lines(["* 1 xfailed *"])
def test_xfail_raises_assertion_error_matches(pytester):
"""Test that xfail works when the expected exception matches"""
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest(
"test_example_xfail.py::test_xfail_raises_assertion_error_matches"
)
result.assert_outcomes(xfailed=1)
result.stdout.fnmatch_lines(["* 1 xfailed *"])
def test_xfail_raises_tuple_matches(pytester):
"""Test that xfail works when one exception in tuple matches"""
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest(
"test_example_xfail.py::test_xfail_raises_tuple_matches"
)
result.assert_outcomes(xfailed=1)
result.stdout.fnmatch_lines(["* 1 xfailed *"])
def test_xfail_raises_multiple_marks_one_matches(pytester):
"""Test that xfail works when one of multiple marks matches"""
pytester.copy_example("examples/test_example_xfail.py")
result = pytester.runpytest(
"test_example_xfail.py::test_xfail_raises_multiple_marks_one_matches"
)
result.assert_outcomes(xfailed=1)
result.stdout.fnmatch_lines(["* 1 xfailed *"])
def test_xfail_mypy(pytester):
pytester.copy_example("examples/test_example_mypy_fail.py")
result = pytester.runpytest("test_example_mypy_fail.py")
result.assert_outcomes(xfailed=5)
result.stdout.fnmatch_lines(["* 5 xfailed *"])
|