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 #1890, which needs to
be fixed/addressed in another way
(#5996).

Fixes #5991.
  • Loading branch information
blueyed committed Oct 21, 2019
1 parent fbb7f66 commit fac9331
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 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``.
23 changes: 1 addition & 22 deletions src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,29 +187,8 @@ def addSuccess(self, testcase):
def stopTest(self, testcase):
pass

def _handle_skip(self):
# implements the skipping machinery (see #2137)
# analog to pythons Lib/unittest/case.py:run
testMethod = getattr(self._testcase, self._testcase._testMethodName)
if getattr(self._testcase.__class__, "__unittest_skip__", False) or getattr(
testMethod, "__unittest_skip__", False
):
# If the class or method was skipped.
skip_why = getattr(
self._testcase.__class__, "__unittest_skip_why__", ""
) or getattr(testMethod, "__unittest_skip_why__", "")
self._testcase._addSkip(self, self._testcase, skip_why)
return True
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", "*= 2 skipped in *"]
)
result.stdout.fnmatch_lines_random(
[
"SKIPPED [1] test_pdb_unittest_skip.py:5: Skipping also with pdb active",
"SKIPPED [1] test_pdb_unittest_skip.py:15: skip_two",
]
)

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

0 comments on commit fac9331

Please sign in to comment.