Skip to content

Commit

Permalink
Do not call TestCase.tearDown for skipped TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobuddel committed Jun 21, 2022
1 parent fab696d commit 9d72bc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/_pytest/unittest.py
Expand Up @@ -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
14 changes: 13 additions & 1 deletion testing/test_unittest.py
Expand Up @@ -1265,12 +1265,24 @@ def tearDown(self):
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 == []


Expand Down

0 comments on commit 9d72bc4

Please sign in to comment.