Skip to content

Commit fac9331

Browse files
committed
unittest: do not use TestCase.debug with --pdb
Reverts #1890, which needs to be fixed/addressed in another way (#5996). Fixes #5991.
1 parent fbb7f66 commit fac9331

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

changelog/5991.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not use ``TestCase.debug()`` for unittests with ``--pdb``.

src/_pytest/unittest.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -187,29 +187,8 @@ def addSuccess(self, testcase):
187187
def stopTest(self, testcase):
188188
pass
189189

190-
def _handle_skip(self):
191-
# implements the skipping machinery (see #2137)
192-
# analog to pythons Lib/unittest/case.py:run
193-
testMethod = getattr(self._testcase, self._testcase._testMethodName)
194-
if getattr(self._testcase.__class__, "__unittest_skip__", False) or getattr(
195-
testMethod, "__unittest_skip__", False
196-
):
197-
# If the class or method was skipped.
198-
skip_why = getattr(
199-
self._testcase.__class__, "__unittest_skip_why__", ""
200-
) or getattr(testMethod, "__unittest_skip_why__", "")
201-
self._testcase._addSkip(self, self._testcase, skip_why)
202-
return True
203-
return False
204-
205190
def runtest(self):
206-
if self.config.pluginmanager.get_plugin("pdbinvoke") is None:
207-
self._testcase(result=self)
208-
else:
209-
# disables tearDown and cleanups for post mortem debugging (see #1890)
210-
if self._handle_skip():
211-
return
212-
self._testcase.debug()
191+
self._testcase(result=self)
213192

214193
def _prunetraceback(self, excinfo):
215194
Function._prunetraceback(self, excinfo)

testing/test_pdb.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def flush(child):
160160
child.wait()
161161
assert not child.isalive()
162162

163+
@pytest.mark.xfail(reason="running .debug() all the time is bad (#5991)")
163164
def test_pdb_unittest_postmortem(self, testdir):
164165
p1 = testdir.makepyfile(
165166
"""
@@ -181,21 +182,37 @@ def test_false(self):
181182
self.flush(child)
182183

183184
def test_pdb_unittest_skip(self, testdir):
184-
"""Test for issue #2137"""
185+
"""Test for issues #2137 and #5991"""
185186
p1 = testdir.makepyfile(
186187
"""
187188
import unittest
189+
188190
@unittest.skipIf(True, 'Skipping also with pdb active')
189191
class MyTestCase(unittest.TestCase):
190192
def test_one(self):
191193
assert 0
194+
195+
class MyOtherTestCase(unittest.TestCase):
196+
def setUp(self):
197+
print("\\nsetUp_called\\n")
198+
199+
def tearDown(self):
200+
print("\\ntearDown_called\\n")
201+
202+
def test_two(self):
203+
self.skipTest("skip_two")
192204
"""
193205
)
194-
child = testdir.spawn_pytest("-rs --pdb %s" % p1)
195-
child.expect("Skipping also with pdb active")
196-
child.expect("1 skipped in")
197-
child.sendeof()
198-
self.flush(child)
206+
result = testdir.runpytest("-s", "-rs", "--pdb", str(p1))
207+
result.stdout.fnmatch_lines(
208+
["setUp_called", "tearDown_called", "*= 2 skipped in *"]
209+
)
210+
result.stdout.fnmatch_lines_random(
211+
[
212+
"SKIPPED [1] test_pdb_unittest_skip.py:5: Skipping also with pdb active",
213+
"SKIPPED [1] test_pdb_unittest_skip.py:15: skip_two",
214+
]
215+
)
199216

200217
def test_pdb_print_captured_stdout_and_stderr(self, testdir):
201218
p1 = testdir.makepyfile(

0 commit comments

Comments
 (0)