I have a module that imports unittest and has some TestCases. I would like
to accept some command-line options (for example below, the name of a data file),
but when I try to pass the option I get the message option -i not recognized
. Is it possible to have unittest
+ provide options to the app (note: I'm using optparse
to handle the options)? Thanks.
$ python test_app_data.py -i data_1.txt
option -i not recognized
=====================
follow-up: this is an implementation of the suggested solution:
import cfg_master #has the optparse option-handling code
...
if __name__ == '__main__':
#add you app's options here...
options_tpl = ('-i', '--in_dir', '-o', '--out_dir')
del_lst = []
for i,option in enumerate(sys.argv):
if option in options_tpl:
del_lst.append(i)
del_lst.append(i+1)
del_lst.reverse()
for i in del_lst:
del sys.argv[i]
unittest.main()