i am using the ConfigParser to read a INI File in a Python (2.7) Project. Now i want to write a Unittest and i am not sure what is the cleanest way to test it.
i already tried to adapt the init-method of the class which is reading the INI file, so i can pass the file which should be used as a parameter. like this:
def __ini__(self, config_file='/src/config/my_conf.ini'):
self.conf = ConfigParser.SafeConfigParser()
self.conf.read(config_file)
it works fine in production. However i do not manage to run it in a unittest. The config file is never available. It doesn't matter if i use the default value or change it to '/test/config/my_conf.ini'. I would prefer to use relative paths.
Could someone tell me what i am doing wrong with the path in the unittest. Or does someone have a much better idea how to handle this?
Thanks a lot!