I have multiple tests in 2 directories:
- test
- app (folder)
- xap (folder)
- run_tests (file to start)
In app and xap folders are tests. One class per module structured like:
class StepTestCase(unittest.TestCase):
def test_add_step(self):
....
def test_failure_in_post(self):
....
in run_tests I have the following code:
loader = unittest.TestLoader()
suite = unittest.TestSuite()
suite.addTests(loader.discover("app", "*test.py", top_level_dir=folder))
suite.addTests(loader.discover("xapp", "*test.py", top_level_dir=folder))
test_runner = xmlrunner.XMLTestRunner(output=output_file)
The issue is that loader.discover doesn't add all tests in one suite but create multiple suites:
unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<app.step_test.StepTestCase testMethod=test_add_step>, <app.step_test.StepTestCase testMethod=test_failure_in_post>]>]>, <unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<app.composite_step_test.CompositeStepTestCase testMethod=test_add_compositestep>, ....]
This is problematic because when it is passed to xmlrunner.XMLTestRunner is actually creating multiple xml file definitions in the same file which is wrong and can't be parsed/checked being invalid.
What I want is just one suite with a list of tests.