@@ -518,6 +518,76 @@ def test_1():
518518 assert "1 failed" in rest
519519 self .flush (child )
520520
521+ def test_pdb_interaction_continue_recursive (self , testdir ):
522+ p1 = testdir .makepyfile (
523+ mytest = """
524+ import pdb
525+ import pytest
526+
527+ count_continue = 0
528+
529+ # Simulates pdbpp, which injects Pdb into do_debug, and uses
530+ # self.__class__ in do_continue.
531+ class CustomPdb(pdb.Pdb):
532+ def do_debug(self, arg):
533+ import sys
534+ import types
535+
536+ newglobals = {
537+ 'Pdb': self.__class__, # NOTE: different with pdb.Pdb
538+ 'sys': sys,
539+ }
540+ if sys.version_info < (3, ):
541+ do_debug_func = pdb.Pdb.do_debug.im_func
542+ else:
543+ do_debug_func = pdb.Pdb.do_debug
544+
545+ orig_do_debug = types.FunctionType(
546+ do_debug_func.__code__, newglobals,
547+ do_debug_func.__name__, do_debug_func.__defaults__,
548+ )
549+ return orig_do_debug(self, arg)
550+ do_debug.__doc__ = pdb.Pdb.do_debug.__doc__
551+
552+ def do_continue(self, *args, **kwargs):
553+ global count_continue
554+ count_continue += 1
555+ return super(CustomPdb, self).do_continue(*args, **kwargs)
556+
557+ def foo():
558+ print("print_from_foo")
559+
560+ def test_1():
561+ i = 0
562+ print("hello17")
563+ pytest.set_trace()
564+ x = 3
565+ print("hello18")
566+
567+ assert count_continue == 2, "unexpected_failure: %d != 2" % count_continue
568+ pytest.fail("expected_failure")
569+ """
570+ )
571+ child = testdir .spawn_pytest ("--pdbcls=mytest:CustomPdb %s" % str (p1 ))
572+ child .expect (r"PDB set_trace \(IO-capturing turned off\)" )
573+ child .expect (r"\n\(Pdb" )
574+ child .sendline ("debug foo()" )
575+ child .expect ("ENTERING RECURSIVE DEBUGGER" )
576+ child .expect (r"\n\(\(Pdb" )
577+ child .sendline ("c" )
578+ child .expect ("LEAVING RECURSIVE DEBUGGER" )
579+ assert b"PDB continue" not in child .before
580+ assert b"print_from_foo" in child .before
581+ child .sendline ("c" )
582+ child .expect (r"PDB continue \(IO-capturing resumed\)" )
583+ rest = child .read ().decode ("utf8" )
584+ assert "hello17" in rest # out is captured
585+ assert "hello18" in rest # out is captured
586+ assert "1 failed" in rest
587+ assert "Failed: expected_failure" in rest
588+ assert "AssertionError: unexpected_failure" not in rest
589+ self .flush (child )
590+
521591 def test_pdb_without_capture (self , testdir ):
522592 p1 = testdir .makepyfile (
523593 """
0 commit comments