Skip to content

Commit 10a6ed1

Browse files
committed
Update unittest test to expect failure for an unexpected success
1 parent 4fc20d0 commit 10a6ed1

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

testing/test_unittest.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,23 +588,37 @@ def test_hello(self, arg1):
588588
assert result.ret == 1
589589

590590
@pytest.mark.skipif("sys.version_info < (2,7)")
591-
def test_unittest_unexpected_failure(testdir):
591+
def test_unittest_expected_failure_for_failing_test_is_xfail(testdir):
592592
testdir.makepyfile("""
593593
import unittest
594594
class MyTestCase(unittest.TestCase):
595595
@unittest.expectedFailure
596-
def test_func1(self):
597-
assert 0
596+
def test_failing_test_is_xfail(self):
597+
assert False
598+
""")
599+
result = testdir.runpytest("-rxX")
600+
result.stdout.fnmatch_lines([
601+
"*XFAIL*MyTestCase*test_failing_test_is_xfail*",
602+
"*1 xfailed*",
603+
])
604+
assert result.ret == 0
605+
606+
@pytest.mark.skipif("sys.version_info < (2,7)")
607+
def test_unittest_expected_failure_for_passing_test_is_fail(testdir):
608+
testdir.makepyfile("""
609+
import unittest
610+
class MyTestCase(unittest.TestCase):
598611
@unittest.expectedFailure
599-
def test_func2(self):
600-
assert 1
612+
def test_passing_test_is_fail(self):
613+
assert True
601614
""")
602615
result = testdir.runpytest("-rxX")
603616
result.stdout.fnmatch_lines([
604-
"*XFAIL*MyTestCase*test_func1*",
605-
"*XPASS*MyTestCase*test_func2*",
606-
"*1 xfailed*1 xpass*",
617+
"*FAILURES*",
618+
"*MyTestCase*test_passing_test_is_fail*",
619+
"*1 failed*",
607620
])
621+
assert result.ret == 1
608622

609623

610624
@pytest.mark.parametrize('fix_type, stmt', [

0 commit comments

Comments
 (0)