4 class DataDrivenTestCase(unittest
.TestCase
):
7 def generateCases(cls
):
10 generateCases
= classmethod(generateCases
)
14 for case
in cls
.generateCases():
15 if isinstance(case
, tuple):
17 elif isinstance(case
, dict):
24 loadTests
= classmethod(loadTests
)
26 def __init__(self
, description
):
27 unittest
.TestCase
.__init
__(self
, 'runOneTest')
28 self
.description
= description
30 def shortDescription(self
):
31 return '%s for %s' % (self
.__class
__.__name
__, self
.description
)
33 def loadTests(module_name
):
34 loader
= unittest
.defaultTestLoader
35 this_module
= __import__(module_name
, {}, {}, [None])
38 for name
in dir(this_module
):
39 obj
= getattr(this_module
, name
)
40 if (isinstance(obj
, (type, types
.ClassType
)) and
41 issubclass(obj
, unittest
.TestCase
)):
42 if hasattr(obj
, 'loadTests'):
43 tests
.extend(obj
.loadTests())
45 tests
.append(loader
.loadTestsFromTestCase(obj
))
47 return unittest
.TestSuite(tests
)