[3.13] gh-121018: Ensure ArgumentParser.parse_args with exit_on_error=False raises instead of exiting when given unrecognized arguments (GH-121019) by miss-islington · Pull Request #121032 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-121018: Ensure ArgumentParser.parse_args with exit_on_error=False …
…raises instead of exiting when given unrecognized arguments (GH-121019)

(cherry picked from commit 0654336)

Co-authored-by: blhsing <blhsing@gmail.com>
  • Loading branch information
blhsing authored and miss-islington committed Jun 26, 2024
commit c8e2d55e218309800a3f1dcc38c1290a0be960c0
6 changes: 4 additions & 2 deletions Lib/argparse.py
3 changes: 3 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6096,6 +6096,9 @@ def test_exit_on_error_with_bad_args(self):
with self.assertRaises(argparse.ArgumentError):
self.parser.parse_args('--integers a'.split())

def test_exit_on_error_with_unrecognized_args(self):
with self.assertRaises(argparse.ArgumentError):
self.parser.parse_args('--foo bar'.split())

def tearDownModule():
# Remove global references to avoid looking like we have refleaks.
Expand Down