Do not call TestCase.tearDown for skipped TestCase

Fix #10060
This commit is contained in:
Hugo Buddelmeijer 2022-06-21 15:12:29 +02:00
parent fab696dcd1
commit 9d72bc48ee
2 changed files with 21 additions and 3 deletions

View File

@ -410,5 +410,11 @@ def check_testcase_implements_trial_reporter(done: List[int] = []) -> None:
def _is_skipped(obj) -> bool:
"""Return True if the given object has been marked with @unittest.skip."""
return bool(getattr(obj, "__unittest_skip__", False))
"""Return True if the given object has been marked with @unittest.skip.
Also return True if obj is a method of a skipped object.
"""
skipped = bool(getattr(obj, "__unittest_skip__", False))
if isinstance(obj, types.MethodType):
skipped |= _is_skipped(obj.__self__)
return skipped

View File

@ -1265,12 +1265,24 @@ def test_pdb_teardown_skipped(
def test_1(self):
pass
{mark}("skipped for other reasons")
class MyTestCase2(unittest.TestCase):
def setUp(self):
pytest.test_pdb_teardown_skipped.append("setUp:" + self.id())
def tearDown(self):
pytest.test_pdb_teardown_skipped.append("tearDown:" + self.id())
def test_2(self):
pass
""".format(
mark=mark
)
)
result = pytester.runpytest_inprocess("--pdb")
result.stdout.fnmatch_lines("* 1 skipped in *")
result.stdout.fnmatch_lines("* 2 skipped in *")
assert tracked == []