TestSuite with testsuites and testcases
You could give some additional information like the structure of your program / test cases and suites. The way I do it is define a suite() for each module. So I have say for UserServiceTest module:
def suite(): """ Gather all the tests from this module in a test suite. """ test_suite = unittest.TestSuite() test_suite.addTest(unittest.makeSuite(UserServiceTest)) return test_suiteif __name__ == "__main__": #So you can run tests from this module individually. unittest.main()
Then I have a main test for each package:
def suite():""" Gather all the tests from this package in a test suite.""" test_suite = unittest.TestSuite() test_suite.addTest(file_tests_main.suite()) test_suite.addTest(userservice_test.suite()) return test_suiteif __name__ == "__main__": #So you can run tests from this package individually. TEST_RUNNER = unittest.TextTestRunner() TEST_SUITE = suite() TEST_RUNNER.run(TEST_SUITE)
You can do this the recursevly until the root of your project. So main test from package A will gather all module in package A + main test from subpackages of package A and so on. I was assuming you-re using unittest
since you didn't give any additional details but I think this structure can be applied to other python testing frameworks as well.
Edit: Well I'm not quite sure I fully understand your problem, but from what I can understand you want to add both the suite defined in suiteFilter.py and the testcase defined in Invoice.py in the same suite? If so why not just do in a mainTest.py for example:
import unittestimport suiteFilterimport Invoicedef suite() test_suite = unittest.TestSuite() test_suite.addTest(suiteFilter.suite()) test_suite.addTest(unittest.makeSuite(Invoice))if __name__ == "__main__": result = unittest.TextTestRunner(verbosity=2).run(suite()) sys.exit(not result.wasSuccessful())
You can add tests and suites all the same to a test_suite.