I have unittests class that I have test methods. Now in in of the methods I temporarily create a file to compare with static file that is inside module. After tests are run, I want to delete that file
Now in setUp
method, I have defined attribute:
self.dir_path
which shows the path to the directory of the file. So To get the file, I can simply write:
'%s/some_file.xls' % self.dir_path
Now to delete it, I would do something like:
os.remove(`%s/some_file.xls` % self.dir_path)
But tearDownClass
is a class method and it won't see self.dir_path
. If I would use inside tearDown
method, then it will try to remove that file after every test (that file is created only in one of the test methods), which would fail.
So what is the best option for such case? Should I just remove that file inside that test method where it is created? I thought to make use of teardown methods functionality which are meant to do just that, but it seems I can't.
Or maybe there is some better way then to temporarily create a file and then delete it after testing?
Note. I need to create that file, because I'm testing reports that are generated in excel format and file is generated with one library, but generated content is checked with another (xlwt
for creation, xlrd
for comparing the result with static excel file).