简体   繁体   中英

save testscase in junit xml format

im trying to run from a tool some tests (python) and i want to save the results in junit xml format, it works fine if im doing it with the unittest.main() function like this:

if __name__ == "__main__":
with open('/path/to/unit_test_results.xml', 'wb') as output:
    unittest.main(
        testRunner=xmlrunner.XMLTestRunner(output=output),
        failfast=False, buffer=False, catchbreak=False)

But i want to do the same without the unittest.main() because i create my testsuite with a parameter like this:

def run_tests_TA(path):
suite = unittest.TestSuite()
suite.addTest(ParametrizedPath.parametrize(TestsTAs, path = path))
unittest.TextTestRunner(verbosity=2).run(suite)

If you have any ideas to help me i'd be very gratefull, thank you!

I did it this way if someone needs:

test_cases = [TestCase('Test1', TestTAs.test_path(path))]
ts = [TestSuite("Results " + os.path.basename(path), test_cases)]

#print(TestSuite.to_xml_string(ts, prettyprint=True))
with open('output.xml', 'w') as f:
    TestSuite.to_file(f, ts)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM