My code runs tests using the unittest
framework. This is the basic idea of what one of my methods looks like:
def _RunTestsList(self, lTestsPaths):
""" Runs all tests in lTestsPaths with the unittest module
"""
for sTestPath in lTestsPaths:
testLoader = unittest.TestLoader()
temp_module = imp.load_source('temp_module', sTestPath)
tstSuite = testLoader.loadTestsFromModule(temp_module)
unittest.TextTestRunner (verbosity=1).run(tstSuite)
What I'm obviously trying to achieve is to run the tests that are in the lTestsPaths
list. For some reason what happens is, instead of running every test in lTestsPaths
individually, it runs every test in addition to all the tests that were run previously. This happens also when calling this method from different places in the code. I.e. all the tests that were previously run (in earlier calls) are run again.
When debugging, I see that when tstSuite
is initialized, it is initialized with all previously run tests.
Why is this happening? How can I make this code run as expected?