[issue10424] better error message from argparse when positionals missing

R. David Murray report at bugs.python.org
Sat Nov 20 04:58:00 CET 2010

R. David Murray <rdmurray at bitdance.com> added the comment:

There are currently no tests in argparse that test the content of error messages, which is fairly standard for stdlib tests since the error messages aren't considered part of the API (only the nature of the exception is).  So there's really no existing test class in test_argparse that would be an appropriate place to put a unit test for this.  

I would instead create a new class.  Perhaps TestErrorContent?  For this test it would probably be best to use assertRaisesRegexp and just check to make sure that the expected list of argument names appears in the message (that is, don't test the contents of the remainder of the message).  You should test several combinations.  (The argparse tests do some fancy footwork around errors, though, so you may not be able to use assertRaisesRegexp directly).

Your approach to the patch, by the way, is an interesting one, and seems to me to make sense.  But I'm not 100% sure I understand the logic of the code you are modifying, so I'll leave it to Steven to comment on that aspect of it :)

Your reference to TestArgumentError reveals a minor bug in the tests: there are actually two test classes named TestArgumentError.  Presumably the second one was indeed supposed to be TestArgumentTypeError.  I've fixed that in r86542.

nosy: +r.david.murray

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list