diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py index 851e4943b23..56330925b41 100644 --- a/src/_pytest/unittest.py +++ b/src/_pytest/unittest.py @@ -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 diff --git a/testing/test_unittest.py b/testing/test_unittest.py index fb312814542..6310f048956 100644 --- a/testing/test_unittest.py +++ b/testing/test_unittest.py @@ -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 == []