Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
In Python, add extra tests to a unittest.main() test run (without depending on global state).
import unittest
def run_tests(data):
extra_tests = create_extra_tests(data)
test_program_class = make_test_program_class(extra_tests)
# In this constructor call you can include any of the arguments supported
# by unittest.main().
test_program_class() # runs tests.
def make_test_program_class(extra_tests):
Return a unittest.TestProgram subclass that adds a list of custom tests.
extra_tests: an iterable of TestCase and TestSuite instances to add in
addition to the usual tests loaded when calling createTests().
class MyTestProgram(unittest.TestProgram):
def createTests(self):
super(MyTestProgram, self).createTests()
return MyTestProgram
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.