From 1f4acaecd11eec275e451357065e631c0c138502 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 20 Oct 2019 23:49:49 +0200 Subject: [PATCH] unittest: do not use `TestCase.debug` with `--pdb` Reverts https://github.com/pytest-dev/pytest/pull/1890, which needs to be fixed/addressed in another way (https://github.com/pytest-dev/pytest/pull/5996). Fixes https://github.com/pytest-dev/pytest/issues/5991. --- changelog/5991.bugfix.rst | 1 + src/_pytest/unittest.py | 8 +------- testing/test_pdb.py | 29 +++++++++++++++++++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 changelog/5991.bugfix.rst diff --git a/changelog/5991.bugfix.rst b/changelog/5991.bugfix.rst new file mode 100644 index 00000000000..1f18e5409af --- /dev/null +++ b/changelog/5991.bugfix.rst @@ -0,0 +1 @@ +Do not use ``TestCase.debug()`` for unittests with ``--pdb``. diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py index 11dc77cc4ff..ac5ae628bc9 100644 --- a/src/_pytest/unittest.py +++ b/src/_pytest/unittest.py @@ -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) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 924c2f4af36..29bb4a329c8 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -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( """ @@ -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(