[docs] [issue31640] Document exit() from parse_args

paul j3 report at bugs.python.org
Thu Oct 12 15:19:21 EDT 2017

paul j3 <ajipanca at gmail.com> added the comment:

And the actual exit is via `parse.error` and `parse.exit`, which are documented in

When run interactively in Ipython, exits (including the help) are captured and displayed with:

In [896]: parser.parse_args()
usage: ipython3 [-h] [--one | --two | --six]
ipython3: error: unrecognized arguments: --pylab --nosep --term-title --InteractiveShellApp.pylab_import_all=False
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2

The exit makes unittesting a challenge.  'test_argparse.py' resolves this by using a subclassed parser, one that changes the error/exit, and also redirects output.

nosy: +paul.j3

Python tracker <report at bugs.python.org>

More information about the docs mailing list