@@ -3089,6 +3089,7 @@ def _run_pdb(self, pdb_args, commands,
30893089 def run_pdb_script (self , script , commands ,
30903090 expected_returncode = 0 ,
30913091 extra_env = None ,
3092+ script_args = None ,
30923093 pdbrc = None ,
30933094 remove_home = False ):
30943095 """Run 'script' lines with pdb and the pdb 'commands'."""
@@ -3106,7 +3107,9 @@ def run_pdb_script(self, script, commands,
31063107 if remove_home :
31073108 homesave = os .environ .pop ('HOME' , None )
31083109 try :
3109- stdout , stderr = self ._run_pdb ([filename ], commands , expected_returncode , extra_env )
3110+ if script_args is None :
3111+ script_args = []
3112+ stdout , stderr = self ._run_pdb ([filename ] + script_args , commands , expected_returncode , extra_env )
31103113 finally :
31113114 if homesave is not None :
31123115 os .environ ['HOME' ] = homesave
@@ -3393,6 +3396,36 @@ def test_issue26053(self):
33933396 self .assertRegex (res , "Restarting .* with arguments:\n a b c" )
33943397 self .assertRegex (res , "Restarting .* with arguments:\n d e f" )
33953398
3399+ def test_issue58956 (self ):
3400+ # Set a breakpoint in a function that already exists on the call stack
3401+ # should enable the trace function for the frame.
3402+ script = """
3403+ import bar
3404+ def foo():
3405+ ret = bar.bar()
3406+ pass
3407+ foo()
3408+ """
3409+ commands = """
3410+ b bar.bar
3411+ c
3412+ b main.py:5
3413+ c
3414+ p ret
3415+ quit
3416+ """
3417+ bar = """
3418+ def bar():
3419+ return 42
3420+ """
3421+ with open ('bar.py' , 'w' ) as f :
3422+ f .write (textwrap .dedent (bar ))
3423+ self .addCleanup (os_helper .unlink , 'bar.py' )
3424+ stdout , stderr = self .run_pdb_script (script , commands )
3425+ lines = stdout .splitlines ()
3426+ self .assertIn ('-> pass' , lines )
3427+ self .assertIn ('(Pdb) 42' , lines )
3428+
33963429 def test_step_into_botframe (self ):
33973430 # gh-125422
33983431 # pdb should not be able to step into the botframe (bdb.py)
@@ -3559,6 +3592,22 @@ def test_run_module_with_args(self):
35593592 stdout , _ = self ._run_pdb (["-m" , "calendar" , "1" ], commands )
35603593 self .assertIn ("December" , stdout )
35613594
3595+ stdout , _ = self ._run_pdb (["-m" , "calendar" , "--type" , "text" ], commands )
3596+ self .assertIn ("December" , stdout )
3597+
3598+ def test_run_script_with_args (self ):
3599+ script = """
3600+ import sys
3601+ print(sys.argv[1:])
3602+ """
3603+ commands = """
3604+ continue
3605+ quit
3606+ """
3607+
3608+ stdout , stderr = self .run_pdb_script (script , commands , script_args = ["--bar" , "foo" ])
3609+ self .assertIn ("['--bar', 'foo']" , stdout )
3610+
35623611 def test_breakpoint (self ):
35633612 script = """
35643613 if __name__ == '__main__':
0 commit comments