diff --git a/AUTHORS b/AUTHORS index 2be74441a27..69f0b47d1be 100644 --- a/AUTHORS +++ b/AUTHORS @@ -31,6 +31,7 @@ Ben Webb Benjamin Peterson Bernard Pratz Bob Ippolito +Brian Choi (bkjchoi72) Brian Dorsey Brian Maissy Brian Okken diff --git a/changelog/3823.bugfix.rst b/changelog/3823.bugfix.rst new file mode 100644 index 00000000000..94fa226c35d --- /dev/null +++ b/changelog/3823.bugfix.rst @@ -0,0 +1 @@ +Fixed the ``--trace`` option so that it works with unittest test cases. diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py index a2fd6ad5afe..66ab1e97282 100644 --- a/src/_pytest/unittest.py +++ b/src/_pytest/unittest.py @@ -182,6 +182,8 @@ def _handle_skip(self): return False def runtest(self): + if self.config.pluginmanager.get_plugin("pdbtrace"): + self.ihook.pytest_pyfunc_call(pyfuncitem=self) if self.config.pluginmanager.get_plugin("pdbinvoke") is None: self._testcase(result=self) else: diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 246f514b4a9..c01a4af8723 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -753,3 +753,21 @@ def test_1(): assert "1 passed" in rest assert "reading from stdin while output" not in rest TestPDB.flush(child) + + def test_unittest_using_trace_invokes_pdb(self, testdir): + p1 = testdir.makepyfile( + """ + import unittest + class Test1(unittest.TestCase): + def test_1(self): + assert True + """ + ) + child = testdir.spawn_pytest("--trace " + str(p1)) + child.expect("test_1") + child.expect("(Pdb)") + child.sendeof() + rest = child.read().decode("utf8") + assert "1 passed" in rest + assert "reading from stdin while output" not in rest + TestPDB.flush(child)