diff options
author | Daniel Hahler <git@thequod.de> | 2018-11-08 22:17:57 +0100 |
---|---|---|
committer | Daniel Hahler <git@thequod.de> | 2019-02-11 14:52:20 +0100 |
commit | 9feb4941f4e57b718427892eab0510069ec453d5 (patch) | |
tree | ad7d306c7051649f024d2ac33643becc8c4d0a84 /testing/test_pdb.py | |
parent | 386e801a5afd0726d658584c145ca087f686026b (diff) | |
download | pytest-9feb4941f4e57b718427892eab0510069ec453d5.tar.gz |
pdb: fix capturing with recursive debugging and pdb++
While I think that pdb++ should be fixed in this regard (by using
`pdb.Pdb`, and not `self.__class__` maybe), this ensures that custom
debuggers like this are working.
Diffstat (limited to 'testing/test_pdb.py')
-rw-r--r-- | testing/test_pdb.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 49fbbad72..43d640614 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -513,6 +513,76 @@ class TestPDB(object): assert "1 failed" in rest self.flush(child) + def test_pdb_interaction_continue_recursive(self, testdir): + p1 = testdir.makepyfile( + mytest=""" + import pdb + import pytest + + count_continue = 0 + + # Simulates pdbpp, which injects Pdb into do_debug, and uses + # self.__class__ in do_continue. + class CustomPdb(pdb.Pdb, object): + def do_debug(self, arg): + import sys + import types + + newglobals = { + 'Pdb': self.__class__, # NOTE: different with pdb.Pdb + 'sys': sys, + } + if sys.version_info < (3, ): + do_debug_func = pdb.Pdb.do_debug.im_func + else: + do_debug_func = pdb.Pdb.do_debug + + orig_do_debug = types.FunctionType( + do_debug_func.__code__, newglobals, + do_debug_func.__name__, do_debug_func.__defaults__, + ) + return orig_do_debug(self, arg) + do_debug.__doc__ = pdb.Pdb.do_debug.__doc__ + + def do_continue(self, *args, **kwargs): + global count_continue + count_continue += 1 + return super(CustomPdb, self).do_continue(*args, **kwargs) + + def foo(): + print("print_from_foo") + + def test_1(): + i = 0 + print("hello17") + pytest.set_trace() + x = 3 + print("hello18") + + assert count_continue == 2, "unexpected_failure: %d != 2" % count_continue + pytest.fail("expected_failure") + """ + ) + child = testdir.spawn_pytest("--pdbcls=mytest:CustomPdb %s" % str(p1)) + child.expect(r"PDB set_trace \(IO-capturing turned off\)") + child.expect(r"\n\(Pdb") + child.sendline("debug foo()") + child.expect("ENTERING RECURSIVE DEBUGGER") + child.expect(r"\n\(\(Pdb") + child.sendline("c") + child.expect("LEAVING RECURSIVE DEBUGGER") + assert b"PDB continue" not in child.before + assert b"print_from_foo" in child.before + child.sendline("c") + child.expect(r"PDB continue \(IO-capturing resumed\)") + rest = child.read().decode("utf8") + assert "hello17" in rest # out is captured + assert "hello18" in rest # out is captured + assert "1 failed" in rest + assert "Failed: expected_failure" in rest + assert "AssertionError: unexpected_failure" not in rest + self.flush(child) + def test_pdb_without_capture(self, testdir): p1 = testdir.makepyfile( """ |