gh-125115: Pass unknown pdb command line args to script instead of fa… · python/cpython@9c2bb7d · GitHub
Skip to content

Commit 9c2bb7d

Browse files
gh-125115: Pass unknown pdb command line args to script instead of fail (#125424)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
1 parent 3ea488a commit 9c2bb7d

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

Lib/pdb.py

Lines changed: 24 additions & 6 deletions

Lib/test/test_pdb.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
@@ -3559,6 +3562,22 @@ def test_run_module_with_args(self):
35593562
stdout, _ = self._run_pdb(["-m", "calendar", "1"], commands)
35603563
self.assertIn("December", stdout)
35613564

3565+
stdout, _ = self._run_pdb(["-m", "calendar", "--type", "text"], commands)
3566+
self.assertIn("December", stdout)
3567+
3568+
def test_run_script_with_args(self):
3569+
script = """
3570+
import sys
3571+
print(sys.argv[1:])
3572+
"""
3573+
commands = """
3574+
continue
3575+
quit
3576+
"""
3577+
3578+
stdout, stderr = self.run_pdb_script(script, commands, script_args=["--bar", "foo"])
3579+
self.assertIn("['--bar', 'foo']", stdout)
3580+
35623581
def test_breakpoint(self):
35633582
script = """
35643583
if __name__ == '__main__':
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)