@@ -604,52 +604,93 @@ def test_1():
604
604
child .expect ("1 passed" )
605
605
self .flush (child )
606
606
607
- @pytest .mark .parametrize ("capture " , (True , False ))
608
- def test_pdb_continue_with_recursive_debug (self , capture , testdir ):
607
+ @pytest .mark .parametrize ("capture_arg " , ("" , "-s" , "-p no:capture" ))
608
+ def test_pdb_continue_with_recursive_debug (self , capture_arg , testdir ):
609
609
"""Full coverage for do_debug without capturing.
610
610
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.
613
613
"""
614
614
p1 = testdir .makepyfile (
615
615
"""
616
+ try:
617
+ input = raw_input
618
+ except NameError:
619
+ pass
620
+
616
621
def set_trace():
617
622
__import__('pdb').set_trace()
618
623
619
- def test_1():
624
+ def test_1(monkeypatch):
625
+ import _pytest.debugging
626
+
627
+ class pytestPDBTest(_pytest.debugging.pytestPDB):
628
+ @classmethod
629
+ def set_trace(cls, *args, **kwargs):
630
+ # Init _PdbWrapper to handle capturing.
631
+ _pdb = cls._init_pdb(*args, **kwargs)
632
+
633
+ # Mock out pdb.Pdb.do_continue.
634
+ import pdb
635
+ pdb.Pdb.do_continue = lambda self, arg: None
636
+
637
+ print("=== SET_TRACE ===")
638
+ assert input() == "debug set_trace()"
639
+
640
+ # Simulate _PdbWrapper.do_debug
641
+ cls._recursive_debug += 1
642
+ print("ENTERING RECURSIVE DEBUGGER")
643
+ print("=== SET_TRACE_2 ===")
644
+
645
+ assert input() == "c"
646
+ _pdb.do_continue("")
647
+ print("=== SET_TRACE_3 ===")
648
+
649
+ # Simulate _PdbWrapper.do_debug
650
+ print("LEAVING RECURSIVE DEBUGGER")
651
+ cls._recursive_debug -= 1
652
+
653
+ print("=== SET_TRACE_4 ===")
654
+ assert input() == "c"
655
+ _pdb.do_continue("")
656
+
657
+ def do_continue(self, arg):
658
+ print("=== do_continue")
659
+ # _PdbWrapper.do_continue("")
660
+
661
+ monkeypatch.setattr(_pytest.debugging, "pytestPDB", pytestPDBTest)
662
+
663
+ import pdb
664
+ monkeypatch.setattr(pdb, "set_trace", pytestPDBTest.set_trace)
665
+
620
666
set_trace()
621
667
"""
622
668
)
623
- if capture :
624
- child = testdir .spawn_pytest ("%s" % p1 )
625
- else :
626
- child = testdir .spawn_pytest ("-s %s" % p1 )
627
- child .expect ("Pdb" )
669
+ child = testdir .spawn_pytest ("%s %s" % (p1 , capture_arg ))
670
+ child .expect ("=== SET_TRACE ===" )
628
671
before = child .before .decode ("utf8" )
629
- if capture :
672
+ if not capture_arg :
630
673
assert ">>> PDB set_trace (IO-capturing turned off) >>>" in before
631
674
else :
632
675
assert ">>> PDB set_trace >>>" in before
633
676
child .sendline ("debug set_trace()" )
634
- child .expect (r"\(Pdb.* " )
677
+ child .expect ("=== SET_TRACE_2 === " )
635
678
before = child .before .decode ("utf8" )
636
679
assert "\r \n ENTERING RECURSIVE DEBUGGER\r \n " in before
637
680
child .sendline ("c" )
638
- child .expect (r"\(Pdb.* " )
681
+ child .expect ("=== SET_TRACE_3 === " )
639
682
640
683
# No continue message with recursive debugging.
641
684
before = child .before .decode ("utf8" )
642
685
assert ">>> PDB continue " not in before
643
- # No extra newline.
644
- assert before .startswith ("c\r \n \r \n --Return--" )
645
686
646
687
child .sendline ("c" )
647
- child .expect ("Pdb " )
688
+ child .expect ("=== SET_TRACE_4 === " )
648
689
before = child .before .decode ("utf8" )
649
690
assert "\r \n LEAVING RECURSIVE DEBUGGER\r \n " in before
650
691
child .sendline ("c" )
651
692
rest = child .read ().decode ("utf8" )
652
- if capture :
693
+ if not capture_arg :
653
694
assert "> PDB continue (IO-capturing resumed) >" in rest
654
695
else :
655
696
assert "> PDB continue >" in rest
0 commit comments