I usually keep my parametric tests as follow
class ShouldCheckSomeCondition(unittest.TestCase):
def __init__(self, parameters...):
...
def runTest():
# given
...
cases = [(p1, ...), (p2, ...), ...]
Then build them at the bottom of the file and create a main to run them:
def suite():
test_suite = unittest.TestSuite()
test_suite.add_tests([ShouldCheckSomeCondition(*params) for params in ShouldCheckSomeCondition.cases])
return test_suite
if __name__ == '__main__':
unittest.TextTestRunner().run(suite())
This is fine and all and I can run a single test file just fine. However, I can't make e.g. Nose to support this. Its discovery tries to build each case and fails. The 'main' is ignored. Does anyone have a good way to run many test files written in such manner? Alternatively, are there other ways to nicely write parametric tests in python so that some test runner will handle it?
since you're working with nose i'd say have a look at parameterized which is a continuation from nose-parameterized