@@ -608,43 +608,88 @@ def test_1():
608608 def test_pdb_continue_with_recursive_debug (self , capture , testdir ):
609609 """Full coverage for do_debug without capturing.
610610
611- This is very similar to test_pdb_interaction_continue_recursive, but
612- simpler, and providing more coverage.
611+ This is very similar to test_pdb_interaction_continue_recursive in general,
612+ but mocks out ``pdb.set_trace`` for providing more coverage.
613613 """
614+
614615 p1 = testdir .makepyfile (
615616 """
617+ try:
618+ input = raw_input
619+ except NameError:
620+ pass
621+
616622 def set_trace():
617623 __import__('pdb').set_trace()
618624
619- def test_1():
625+ def test_1(monkeypatch):
626+ import _pytest.debugging
627+
628+ class pytestPDBTest(_pytest.debugging.pytestPDB):
629+ @classmethod
630+ def set_trace(cls, *args, **kwargs):
631+ # Init _PdbWrapper to handle capturing.
632+ _pdb = cls._init_pdb(*args, **kwargs)
633+
634+ # Mock out pdb.Pdb.do_continue.
635+ import pdb
636+ pdb.Pdb.do_continue = lambda self, arg: None
637+
638+ print("=== SET_TRACE ===")
639+ assert input() == "debug set_trace()"
640+
641+ # Simulate _PdbWrapper.do_debug
642+ cls._recursive_debug += 1
643+ print("ENTERING RECURSIVE DEBUGGER")
644+ print("=== SET_TRACE_2 ===")
645+
646+ assert input() == "c"
647+ _pdb.do_continue("")
648+ print("=== SET_TRACE_3 ===")
649+
650+ # Simulate _PdbWrapper.do_debug
651+ print("LEAVING RECURSIVE DEBUGGER")
652+ cls._recursive_debug -= 1
653+
654+ print("=== SET_TRACE_4 ===")
655+ assert input() == "c"
656+ _pdb.do_continue("")
657+
658+ def do_continue(self, arg):
659+ print("=== do_continue")
660+ # _PdbWrapper.do_continue("")
661+
662+ monkeypatch.setattr(_pytest.debugging, "pytestPDB", pytestPDBTest)
663+
664+ import pdb
665+ monkeypatch.setattr(pdb, "set_trace", pytestPDBTest.set_trace)
666+
620667 set_trace()
621668 """
622669 )
623670 if capture :
624671 child = testdir .spawn_pytest ("%s" % p1 )
625672 else :
626673 child = testdir .spawn_pytest ("-s %s" % p1 )
627- child .expect ("Pdb " )
674+ child .expect ("=== SET_TRACE === " )
628675 before = child .before .decode ("utf8" )
629676 if capture :
630677 assert ">>> PDB set_trace (IO-capturing turned off) >>>" in before
631678 else :
632679 assert ">>> PDB set_trace >>>" in before
633680 child .sendline ("debug set_trace()" )
634- child .expect (r"\(Pdb.* " )
681+ child .expect ("=== SET_TRACE_2 === " )
635682 before = child .before .decode ("utf8" )
636683 assert "\r \n ENTERING RECURSIVE DEBUGGER\r \n " in before
637684 child .sendline ("c" )
638- child .expect (r"\(Pdb.* " )
685+ child .expect ("=== SET_TRACE_3 === " )
639686
640687 # No continue message with recursive debugging.
641688 before = child .before .decode ("utf8" )
642689 assert ">>> PDB continue " not in before
643- # No extra newline.
644- assert before .startswith ("c\r \n \r \n --Return--" )
645690
646691 child .sendline ("c" )
647- child .expect ("Pdb " )
692+ child .expect ("=== SET_TRACE_4 === " )
648693 before = child .before .decode ("utf8" )
649694 assert "\r \n LEAVING RECURSIVE DEBUGGER\r \n " in before
650695 child .sendline ("c" )
0 commit comments