Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ def runtest(self) -> None:
# Arguably we could always postpone tearDown(), but this changes the moment where the
# TestCase instance interacts with the results object, so better to only do it
# when absolutely needed.
if self.config.getoption("usepdb") and not _is_skipped(self.obj):
if self.config.getoption("usepdb") and not (
_is_skipped(self.obj) or _is_skipped(self._testcase)
):
self._explicit_tearDown = self._testcase.tearDown
setattr(self._testcase, "tearDown", lambda *args: None)

Expand Down
39 changes: 39 additions & 0 deletions testing/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,45 @@ def test_1(self):
assert tracked == []


@pytest.mark.parametrize(
"mark",
[
'@unittest.skip("skipped for reasons")',
'@pytest.mark.skip(reason="skipped for reasons")',
],
)
def test_pdb_teardown_skipped_class(
pytester: Pytester, monkeypatch: MonkeyPatch, mark: str
) -> None:
tracked: List[str] = []
monkeypatch.setattr(
pytest, "test_pdb_teardown_skipped_class", tracked, raising=False
)

pytester.makepyfile(
"""
import unittest
import pytest

{mark}
class MyTestCase(unittest.TestCase):

def tearDown(self):
pytest.test_pdb_teardown_skipped_class.append(self.id())

def test_1(self):
pass

""".format(
mark=mark
)
)

result = pytester.runpytest_inprocess("--pdb")
result.stdout.fnmatch_lines("* 1 skipped in *")
assert tracked == []


def test_async_support(pytester: Pytester) -> None:
pytest.importorskip("unittest.async_case")

Expand Down