Skip to content

Commit dc3ac78

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

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
@@ -156,20 +156,31 @@ def test_pdb_unittest_postmortem(self, testdir):
156156
p1 = testdir.makepyfile(
157157
"""
158158
import unittest
159+
160+
teardown_called = 0
161+
159162
class Blub(unittest.TestCase):
160163
def tearDown(self):
161-
self.filename = None
162-
def test_false(self):
164+
global teardown_called
165+
teardown_called += 1
166+
167+
def test_error(self):
163168
self.filename = 'debug' + '.me'
164169
assert 0
170+
171+
def test_check(self):
172+
assert teardown_called == 1
165173
"""
166174
)
167-
child = testdir.spawn_pytest("--pdb %s" % p1)
175+
child = testdir.spawn_pytest(
176+
"--pdb {p1}::Blub::test_error {p1}::Blub::test_check".format(p1=p1)
177+
)
168178
child.expect("Pdb")
169179
child.sendline("p self.filename")
170-
child.sendeof()
180+
child.expect("'debug.me'")
181+
child.sendline("c")
171182
rest = child.read().decode("utf8")
172-
assert "debug.me" in rest
183+
assert "= 1 failed, 1 passed in" in rest
173184
self.flush(child)
174185

175186
def test_pdb_unittest_skip(self, testdir):

0 commit comments

Comments
 (0)