We do something like this to run those tests that are integration (regression) within the unittest framework (in fact, this is an internal setup that gives us huge advantages, such as running tests in parallel in a machine cluster, etc. etc. .d. - the great added value of this setting is why we are so interested in using unittest frameworks).
Each test is presented in a file (parameters for use in this test, followed by expected results). Our Integration_test reads all such files from the directory, analyzes each of them, and then calls:
def addtestmethod(testcase, uut, testname, parameters, expresults): def testmethod(self): results = uut(parameters) self.assertEqual(expresults, results) testmethod.__name__ = testname setattr(testcase, testname, testmethod)
Let's start with an empty test class:
class IntegrationTest(unittest.TestCase): pass
and then call addtestmethod(IntegrationTest, ... in a loop in which we read all the relevant files and parse them to get the name, parameters and expressions.
Finally, we call our own specialized test runner, which does the hard work (distributing tests on available machines in a cluster, collecting results, etc.). We did not want to invent this wheel with a rich added value, so we make a test case as close as possible to a typical "manual encoding" as necessary, in order to "trick" a tester working directly for us -).
If you have specific reasons (good test videos or the like) to use the unittest approach for tests (integration?), You may find that your life is easier with a different approach. Nevertheless, it is quite viable, and we are quite happy with its results (basically these are incredibly fast runs of large sets of integration / regression tests!).