'Target specific unittests and create XML results
I'm trying to work out how to build a unittest runner that allows me to run specific tests and export those results to XML (JUnit). I've found countless examples of each requirement individually, but I've had trouble merging these concepts.
import unittest
from junit_xml import TestSuite as TS
loader = unittest.TestLoader()
suite = loader.discover(test_dir) # eg. test_dir = \folder1
z = TS("my test suite", suite)
print(TS.to_xml_string([z]))
This fails with the following as the suite is a unittest TestSuite object, not a junit_xml TestSuite object.
Exception has occurred: AttributeError 'TestSuite' object has no attribute 'assertions'
So I either need a way to discover tests using junit_xml, load the unittest suite into a junit TestSuite, or go about this from another direction.
My directory structure:
.\runner.py
\folder1
test1.py
\folder2
test2.py
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
