Skip to content

Commit

Permalink
unittest: do not use TestCase.debug with --pdb
Browse files Browse the repository at this point in the history
Reverts pytest-dev#1890, which needs to
be fixed/addressed in another way
(pytest-dev#5996).

Fixes pytest-dev#5991.
  • Loading branch information
blueyed committed Oct 20, 2019
1 parent fbb7f66 commit 1f4acae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog/5991.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not use ``TestCase.debug()`` for unittests with ``--pdb``.
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
29 changes: 23 additions & 6 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def flush(child):
child.wait()
assert not child.isalive()

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

def test_pdb_unittest_skip(self, testdir):
"""Test for issue #2137"""
"""Test for issues #2137 and #5991"""
p1 = testdir.makepyfile(
"""
import unittest
@unittest.skipIf(True, 'Skipping also with pdb active')
class MyTestCase(unittest.TestCase):
def test_one(self):
assert 0
class MyOtherTestCase(unittest.TestCase):
def setUp(self):
print("\\nsetUp_called\\n")
def tearDown(self):
print("\\ntearDown_called\\n")
def test_two(self):
self.skipTest("skip_two")
"""
)
child = testdir.spawn_pytest("-rs --pdb %s" % p1)
child.expect("Skipping also with pdb active")
child.expect("1 skipped in")
child.sendeof()
self.flush(child)
result = testdir.runpytest("-s", "-rs", "--pdb", str(p1))
result.stdout.fnmatch_lines(
[
"setUp_called",
"tearDown_called",
"SKIPPED [1] test_pdb_unittest_skip.py:5: Skipping also with pdb active",
"SKIPPED [1] test_pdb_unittest_skip.py:15: skip_two",
"*= 2 skipped in *",
]
)

def test_pdb_print_captured_stdout_and_stderr(self, testdir):
p1 = testdir.makepyfile(
Expand Down

0 comments on commit 1f4acae

Please sign in to comment.