Skip to content

Commit 1f4acae

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 1f4acae

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,7 @@ def _handle_skip(self):
203203
return False
204204

205205
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()
206+
self._testcase(result=self)
213207

214208
def _prunetraceback(self, excinfo):
215209
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+
[
209+
"setUp_called",
210+
"tearDown_called",
211+
"SKIPPED [1] test_pdb_unittest_skip.py:5: Skipping also with pdb active",
212+
"SKIPPED [1] test_pdb_unittest_skip.py:15: skip_two",
213+
"*= 2 skipped in *",
214+
]
215+
)
199216

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

0 commit comments

Comments
 (0)