Skip to content

Commit

Permalink
unittest: do not use TestCase.debug() with --pdb
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Oct 18, 2019
1 parent 0783030 commit 9d40022
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
8 changes: 1 addition & 7 deletions src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,7 @@ def _handle_skip(self):
return False

def runtest(self):
if self.config.pluginmanager.get_plugin("pdbinvoke") is None:
self._testcase(result=self)
else:
# disables tearDown and cleanups for post mortem debugging (see #1890)
if self._handle_skip():
return
self._testcase.debug()
self._testcase(result=self)

def _prunetraceback(self, excinfo):
Function._prunetraceback(self, excinfo)
Expand Down
21 changes: 16 additions & 5 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,31 @@ def test_pdb_unittest_postmortem(self, testdir):
p1 = testdir.makepyfile(
"""
import unittest
teardown_called = 0
class Blub(unittest.TestCase):
def tearDown(self):
self.filename = None
def test_false(self):
global teardown_called
teardown_called += 1
def test_error(self):
self.filename = 'debug' + '.me'
assert 0
def test_check(self):
assert teardown_called == 1
"""
)
child = testdir.spawn_pytest("--pdb %s" % p1)
child = testdir.spawn_pytest(
"--pdb {p1}::Blub::test_error {p1}::Blub::test_check".format(p1=p1)
)
child.expect("Pdb")
child.sendline("p self.filename")
child.sendeof()
child.expect("'debug.me'")
child.sendline("c")
rest = child.read().decode("utf8")
assert "debug.me" in rest
assert "= 1 failed, 1 passed in" in rest
self.flush(child)

def test_pdb_unittest_skip(self, testdir):
Expand Down

0 comments on commit 9d40022

Please sign in to comment.