-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
pdbpp: fix capturing with recursive debugging #4347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix output capturing when using pdb++ with recursive debugging. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -513,6 +513,76 @@ def test_1(): | |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @blueyed, sorry for the delay. I've tried your branch again on Windows, here's the full session:
Really strange how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is solved? |
||
self.flush(child) | ||
|
||
def test_pdb_without_capture(self, testdir): | ||
p1 = testdir.makepyfile( | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange but I get (apparently) the same interactive session you describe here in this tests without your patch:
Am I missing something? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for testing.
That looks like it is expected, but did not work for me.
Maybe also due to pdbpp instead of pdb.
OTOH, the inner "c" without this patch should get handled with the "do_continue" really though (and then resume capturing, causing pdb to fail then).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least the new test is failing without the patch:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe capturing is stacked in some way on Windows already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally I've thought about having some new attribute to see the level/stacking of suspend/resume on the capman, but it would not really help here - more relevant for #4331 probably.
This comment was marked as resolved.
Sorry, something went wrong.