Skip to content

Commit ab56e0b

Browse files
committed
unittest: do not use TestCase.debug() with --pdb
Fixes pytest-dev#5991.
1 parent c9524af commit ab56e0b

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

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: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,31 @@ def test_pdb_unittest_postmortem(self, testdir):
164164
p1 = testdir.makepyfile(
165165
"""
166166
import unittest
167+
168+
teardown_called = 0
169+
167170
class Blub(unittest.TestCase):
168171
def tearDown(self):
169-
self.filename = None
170-
def test_false(self):
172+
global teardown_called
173+
teardown_called += 1
174+
175+
def test_error(self):
171176
self.filename = 'debug' + '.me'
172177
assert 0
178+
179+
def test_check(self):
180+
assert teardown_called == 1
173181
"""
174182
)
175-
child = testdir.spawn_pytest("--pdb %s" % p1)
183+
child = testdir.spawn_pytest(
184+
"--pdb {p1}::Blub::test_error {p1}::Blub::test_check".format(p1=p1)
185+
)
176186
child.expect("Pdb")
177187
child.sendline("p self.filename")
178-
child.sendeof()
188+
child.expect("'debug.me'")
189+
child.sendline("c")
179190
rest = child.read().decode("utf8")
180-
assert "debug.me" in rest
191+
assert "= 1 failed, 1 passed in" in rest
181192
self.flush(child)
182193

183194
def test_pdb_unittest_skip(self, testdir):

0 commit comments

Comments
 (0)