I\'m writing test cases for argparse implementation. I intend to test \'-h\' feature. The following code does it. But it also outputs the usage for the script. Is there a wa
Some variations on using ['-h'] include:
parser.print_help() # formats the help, prints it and exits
parser.format_help() # format the help without printing or exit
parser.exit # can be modified to not exit, such as for a parser subclass
parser.error # default print usage and call parser.exit
These are part of the public API.
The argparse test file (test_argparse.py) also gives ideas on how to test things. For many tests it uses an ArgumentParser subclass that has its own error method.