Generating tests in Python unittest
There are many applications where you want to apply a code to a variety of data sets, and verify that you get the correct output. In this context, what you want is a test generator, which can dynamically create tests, based on the set of data sets that are available for testing. Unfortunately, this does not appear to be a feature of unittest . The closest I have seen to this, is the support for test generators in the nose package, which extends unittest to provide test discovery mechanisms. However, that test generation feature is somewhat limited; it only applies to test functions that are Python generators, and not to similar class methods. The following example shows how to directly insert new test methods into a unittest.TestCase class : # # A simple example for generating tests in the Python unittest framework # import glob import unittest # # Defining the class that will contain the new tests # class TestCases(unittest.TestCase): pass # # A generic function that performs a te...