jeudi 28 juillet 2016

How do i write a mock configuration file in the setUp for my unittesting?

I am trying to make my setUp-method create a mock configuration file, write a bunch of mock variables to it, and then use this file to instantiate the class (called Producer) i am running my tests on.

path_to_file =("/path/to/unit.Config")
unitTest = open (path_to_file, 'w')
unitTest.write("a string containing mock variables")
prod = Producer("unit.Config")

The tests work if i manually create a file and fill it with data prior to running the tests, but doing it in setUp causes my program to crash ("Producer instance has no attribute 'LOGGER'). If i remove the 3 first lines of code the tests will run fine - so writing to the config file works.

Aucun commentaire:

Enregistrer un commentaire