I am using Python's unittest with simple code like so:
suite = unittest.TestSuite()
suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(module1))
suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(module2))
However, I am wanting to do some custom things to each test after they have been gathered by the suite. I thought I could do something like this to iterate over the test cases in suite:
print suite.countTestCases()
for test in suite: # Also tried with suite.__iter__()
# Do something with test
print test.__class__
However, for as many test cases as I load, it only ever prints
3
<class 'unittest.suite.TestSuite'>
Is there a way I can get all the objects of class TestCase from the suite? Is there some other way I should be loading test cases to facilitate this?
Try
for test in suite:
print test._tests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With