Skip to content

Commit 7c6096e

Browse files
committed
Better demonstrate the error messages produced
1 parent e07e25b commit 7c6096e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Lib/test/test_argparse.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,23 @@ def test_required_subparsers_no_destination_error(self):
19381938
parser = ErrorRaisingArgumentParser()
19391939
subparsers = parser.add_subparsers()
19401940
subparsers.add_parser('run')
1941-
self.assertArgumentParserError(parser.parse_args, ())
1941+
with self.assertRaises(ArgumentParserError) as excinfo:
1942+
parser.parse_args(())
1943+
self.assertRegex(
1944+
excinfo.exception.stderr,
1945+
'error: the following arguments are required: {run}\n$'
1946+
)
1947+
1948+
def test_wrong_argument_subparsers_no_destination_error(self):
1949+
parser = ErrorRaisingArgumentParser()
1950+
subparsers = parser.add_subparsers()
1951+
subparsers.add_parser('foo')
1952+
with self.assertRaises(ArgumentParserError) as excinfo:
1953+
parser.parse_args(('bar',))
1954+
self.assertRegex(
1955+
excinfo.exception.stderr,
1956+
r"error: argument {foo}: invalid choice: 'bar' \(choose from 'foo'\)\n$"
1957+
)
19421958

19431959
def test_optional_subparsers(self):
19441960
parser = ErrorRaisingArgumentParser()

0 commit comments

Comments
 (0)