unittest: how to specify which suites to run with unittest.main()?

Peter Hansen peter at engcorp.com
Wed Feb 12 08:44:04 EST 2003


Fernando Perez wrote:
> 
> mysuite = makeSuite(test1)
> mysuite.addTests(makeSuite(test2))
> 
> but that doesn't work. Furthermore, main() seems to want to run _all_
> subclasses of TestCase.

Here's a slightly modified example from work which I hope will help you
with the solution.  Note that the group here chose to make the test
functions start with "check" instead of "test" but I believe you
will have no trouble translating to your own situation.

def suite():
    return unittest.TestSuite((
        unittest.makeSuite(SetupFileImportTestCase, 'check'),
        unittest.makeSuite(FunctionTestCase, 'check'),
        ))


if __name__ == '__main__':
    unittest.main(defaultTest='suite')

-Peter




More information about the Python-list mailing list