55import sys
66import unittest
77import subprocess
8+ import textwrap
89
910from test import support
1011# This little helper class is essential for testing pdb under doctest.
@@ -595,6 +596,22 @@ def test_pdb_run_with_code_object():
595596
596597class PdbTestCase (unittest .TestCase ):
597598
599+ def run_pdb (self , script , commands ):
600+ """Run 'script' lines with pdb and the pdb 'commands'."""
601+ filename = 'main.py'
602+ with open (filename , 'w' ) as f :
603+ f .write (textwrap .dedent (script ))
604+ cmd = [sys .executable , '-m' , 'pdb' , filename ]
605+ stdout = stderr = None
606+ with subprocess .Popen (cmd , stdout = subprocess .PIPE ,
607+ stdin = subprocess .PIPE ,
608+ stderr = subprocess .STDOUT ,
609+ ) as proc :
610+ stdout , stderr = proc .communicate (str .encode (commands ))
611+ stdout = stdout and bytes .decode (stdout )
612+ stderr = stderr and bytes .decode (stderr )
613+ return stdout , stderr
614+
598615 def test_issue7964 (self ):
599616 # open the file as binary so we can force \r\n newline
600617 with open (support .TESTFN , 'wb' ) as f :
@@ -610,6 +627,40 @@ def test_issue7964(self):
610627 self .assertNotIn (b'SyntaxError' , stdout ,
611628 "Got a syntax error running test script under PDB" )
612629
630+ def test_issue13183 (self ):
631+ script = """
632+ from bar import bar
633+
634+ def foo():
635+ bar()
636+
637+ def nope():
638+ pass
639+
640+ def foobar():
641+ foo()
642+ nope()
643+
644+ foobar()
645+ """
646+ commands = """
647+ from bar import bar
648+ break bar
649+ continue
650+ step
651+ step
652+ quit
653+ """
654+ bar = """
655+ def bar():
656+ print('1')
657+ """
658+ with open ('bar.py' , 'w' ) as f :
659+ f .write (textwrap .dedent (bar ))
660+ stdout , stderr = self .run_pdb (script , commands )
661+ self .assertIn ('main.py(5)foo()->None' , stdout .split ('\n ' )[- 3 ],
662+ 'Fail to step into the caller after a return' )
663+
613664 def tearDown (self ):
614665 support .unlink (support .TESTFN )
615666
0 commit comments