Hello all,<br><br>Does anyone have advice for writing unit tests against variables set by command-line options?<br><br>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:<br>
<br><<snipped argparse import and options setup >><br>mode = p.parse_args() #always set to either --debug or --live<br><br>if mode.live:<br>
recipients = ['<a href="mailto:jsmith@email.com">jsmith@email.com</a>', '<a href="mailto:janedoe@email.com">janedoe@email.com</a>']<br>
# set logging to a file<br>
elif mode.debug:<br>
recipients = ['<a href="mailto:admin@admin.com">admin@admin.com</a>']<br>
# log to stdout<br><br>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. <br>
<br>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? <br><br>I'd greatly appreciate it.<br>Serdar<br>