Pytest reporting in JUnit XML format



pytest --junitxml report.xml


examples/pytest/reporting/report.xml
<?xml version="1.0" ?>
<testsuites>
    <testsuite name="pytest" errors="0" failures="1" skipped="1" tests="5" time="0.049" timestamp="2021-03-03T22:42:49.080442" hostname="code-maven">
        <testcase classname="test_colors" name="test_blue" time="0.001"/>
        <testcase classname="test_colors" name="test_red" time="0.001">
            <failure message="assert 1 == 2
  +1
  -2">def test_red():
&gt;       assert 1 == 2
E       assert 1 == 2
E         +1
E         -2

test_colors.py:7: AssertionError</failure>
        </testcase>
        <testcase classname="test_colors" name="test_purple" time="0.000">
            <skipped type="pytest.skip" message="So we can show skip reporting">/home/gabor/work/slides/python/examples/pytest/reporting/test_colors.py:9: So we can show skip reporting</skipped>
        </testcase>
        <testcase classname="test_colors" name="test_orange" time="0.000"/>
        <testcase classname="test_colors" name="test_green" time="0.000"/>
    </testsuite>
</testsuites>

To make the XML more himan-readable:


cat report.xml | python -c 'import sys;import xml.dom.minidom;s=sys.stdin.read();print(xml.dom.minidom.parseString(s).toprettyxml())'