I have python scripts which are run with a config file on CLI. All the contents of the test script are inside class "ABC".
In the init of class ABC, I pass config file which gets used in the script.
So when I run my python script standalone I would say "python script_one.py -c config.cfg"
Now the issue is that I need to run all the python tests in the directory using nosetests. The libraries of nose tests do not like the fact that I am passing "config" in the init() of class ABC.
I need a way of running the python as mentioned above with config and also as nosetests.
I switched to ConfigParser module in Python which parses config files and I do not have to pass them to the init()
class TestMe(object):
def __init__(self):
config = ConfigParser.ConfigParser()
config.read(file)
config file is being referenced in main():
if __name__ == '__main__':
#config = c.parse_config()
#test = TestMe(config)
file = "configs/test_config.yaml"
print "inside main..."
config = ConfigParser.ConfigParser()
config.read(file)
If config=c.parse_config() and test=TestMe(config) had been used, then I would had to pass my config file (xyz.cfg) as "script_1.py -c xyz.cfg) - is there a way to leverage this in nose tests? I ask this because nose tests wont let me pass "config" to init() of the class TestMe.
The config.read(file) leads to an error when I do "nosetests script_1.py"
E
======================================================================
ERROR: Failure: TypeError ('type' object is not iterable)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/nose/loader.py", line 519, in makeTest
return self._makeTest(obj, parent)
File "/usr/local/lib/python2.7/site-packages/nose/loader.py", line 578, in _makeTest
return MethodTestCase(obj)
File "/usr/local/lib/python2.7/site-packages/nose/case.py", line 345, in __init__
self.inst = self.cls()
File "/home/..../script_1.py", line 30, in __init__
config.read(file)
File "/usr/local/lib/python2.7/ConfigParser.py", line 300, in read
for filename in filenames:
TypeError: 'type' object is not iterable
Is there a way I can run my scripts standalone with config and also with nosetests?