Created
January 2, 2012 13:54
-
-
Save lprsd/1550761 to your computer and use it in GitHub Desktop.
Create Test Cases Dynamically, in Python.
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 unittest2 as unittest | |
def get_verify_mtd(sum_tuple, sum_value): | |
def test1(self): | |
self.assertEqual(sum(sum_tuple),sum_value) | |
return test1 | |
def create_test_case_class(): | |
sumlist = range(20,30,2) | |
sum1_list = [20]*5 | |
sum2_list = range(0,10,2) | |
sum3_list = zip(sum1_list,sum2_list) | |
input_list = zip(sum3_list,sumlist) | |
mtd_dict = {} | |
for element in input_list: | |
mtd_dict['test_%s'%element[1]] = get_verify_mtd(*element) | |
print mtd_dict | |
return type('TestSums',(unittest.TestCase,),mtd_dict) | |
def load_tests(loader, tests, pattern): | |
suite = unittest.TestSuite() | |
case1 = loader.loadTestsFromTestCase(create_test_case_class()) | |
suite.addTests(case1) | |
return suite |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
discussion on twitter