Created
May 16, 2012 04:19
-
-
Save cjerdonek/2707352 to your computer and use it in GitHub Desktop.
In Python, add extra tests to a unittest.main() test run (without depending on global state).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
Arguments: | |
extra_tests: an iterable of TestCase and TestSuite instances to add in | |
addition to the usual tests loaded when calling createTests(). | |
cf. http://docs.python.org/py3k/library/unittest.html#unittest.TestSuite.addTests | |
""" | |
class MyTestProgram(unittest.TestProgram): | |
def createTests(self): | |
super(MyTestProgram, self).createTests() | |
self.test.addTests(extra_tests) | |
return MyTestProgram |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment