[Tutor] Unit testing command-line options from argparse or optparse
zstumgoren at gmail.com
Tue May 18 22:49:15 CEST 2010
Does anyone have advice for writing unit tests against variables set by
I have a program I'd like to run in either "debug" or "live" mode, with
various settings associated with each. Below is some pseudo-code that shows
what I'd like to do:
<<snipped argparse import and options setup >>
mode = p.parse_args() #always set to either --debug or --live
recipients = ['jsmith at email.com', 'janedoe at email.com']
# set logging to a file
recipients = ['admin at admin.com']
# log to stdout
The "live" and "debug" attributes are set by command-line flags passed to
the argparse module. What I'd like to do is write tests that check whether
various settings (recipients, logging, etc.) are configured properly based
on the command-line options.
But if "mode" is not set until runtime, I clearly can't import it into my
suite of unit tests, right? Is there some standard testing approach to this
problem (perhaps mocking?) that you all can recommend?
I'd greatly appreciate it.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor