I am trying to supply command line arguments to Python unittest
and facing some issues.
I have searched on internet and found a way to supply arguments as
unittest.main(argv=[myArg])
The issue is this works fine for single command line argument but fails for more than one arguments.
unittest.main(argv=[myArg1, myArg2, myArg3])
Above call fails with below error:
File "/opt/python2.6.6/lib/python2.6/unittest.py", line 816, in __init__
self.parseArgs(argv)
File "/opt/python2.6.6/lib/python2.6/unittest.py", line 843, in parseArgs
self.createTests()
File "/opt/python2.6.6/lib/python2.6/unittest.py", line 849, in createTests
self.module)
File "/opt/python2.6.6/lib/python2.6/unittest.py", line 613, in
loadTestsFromNames suites = [self.loadTestsFromName(name, module)
for name in names]
File "/opt/python2.6.6/lib/python2.6/unittest.py", line 584, in
loadTestsFromName parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'admin'
Digged more into this and found that Python unittest
treats everything sent using argv
as test case to be run.
Please let me know If there's still a way to supply more than one arguement to my unit test cases. I want to override some hard coded values like IP address, test case tag etc. and essentially run this test script from within main test script.
Thanks in advance.