@@ -3089,6 +3089,7 @@ def _run_pdb(self, pdb_args, commands,
3089
3089
def run_pdb_script (self , script , commands ,
3090
3090
expected_returncode = 0 ,
3091
3091
extra_env = None ,
3092
+ script_args = None ,
3092
3093
pdbrc = None ,
3093
3094
remove_home = False ):
3094
3095
"""Run 'script' lines with pdb and the pdb 'commands'."""
@@ -3106,7 +3107,9 @@ def run_pdb_script(self, script, commands,
3106
3107
if remove_home :
3107
3108
homesave = os .environ .pop ('HOME' , None )
3108
3109
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 )
3110
3113
finally :
3111
3114
if homesave is not None :
3112
3115
os .environ ['HOME' ] = homesave
@@ -3393,6 +3396,36 @@ def test_issue26053(self):
3393
3396
self .assertRegex (res , "Restarting .* with arguments:\n a b c" )
3394
3397
self .assertRegex (res , "Restarting .* with arguments:\n d e f" )
3395
3398
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
+
3396
3429
def test_step_into_botframe (self ):
3397
3430
# gh-125422
3398
3431
# pdb should not be able to step into the botframe (bdb.py)
@@ -3559,6 +3592,22 @@ def test_run_module_with_args(self):
3559
3592
stdout , _ = self ._run_pdb (["-m" , "calendar" , "1" ], commands )
3560
3593
self .assertIn ("December" , stdout )
3561
3594
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
+
3562
3611
def test_breakpoint (self ):
3563
3612
script = """
3564
3613
if __name__ == '__main__':
0 commit comments