You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since this should be a drop-in replacement for unittest, I reviewed the unittest-xml-reporting plugin to see how it handles subtests in their JUnit XML:
<testcase classname="samples.test_sample_unittest.SampleTestSuite" name="test_unittest_subtests (number=0)" time="0.000" timestamp="0001-01-01T00:00:00" file="samples/test_sample_unittest.py" line="59">
<!--Simple test with subtests-->
<failure type="AssertionError" message="0 is not true : 0 should be odd"><![CDATA[Traceback (most recent call last):
File "/Users/dambrosi/Documents/GitHub/hpc-shs-qa/samples/test_sample_unittest.py", line 64, in test_unittest_subtests
self.assertTrue(number % 2, f"{number} should be odd")
AssertionError: 0 is not true : 0 should be odd
]]></failure>
</testcase>
I don't love their handling. They only list subtests if there is a failed one. So either:
If 1 or more subtests failed, ONLY failed subtests are reported in the XML. The top-level test is NOT reported.
If all subtests passed, NO subtests are reported in the XML, only the top-level test is reported as passing.
xmlrunner README does call out that it is considered "limited support of subtests". So IMHO, this is a chance for pytest to improve, since there are open issues related to xmlrunner showing community desire for it. By reporting ALL subtests AND the parent test, pass or fail. This way reports are consistent between runs.
I would like to work on the JUnit XML reporting side of this. I plan to investigate separate, schema-valid testcase entries for subtests, with stable names and correct parent/subtest accounting, and add pytester coverage for passing, failing, skipped, and unittest-style subtests while keeping ordinary test output compatible.
I did not find an open PR for this issue in the linked activity or current JUnit/subtest PR search. Please let me know if someone is already implementing it or if there are naming/accounting constraints to follow. Development will use Codex assistance; the resulting patch will need human review before submission.
Activity
codambro commentedon Nov 4, 2025
I can see in junitxml, there is some caching by nodeid
A SubtestReport will have the same nodeid as the parent. So when we call "_opentestcase" for each subtest, they all use the same cached NodeReporter
nicoddemus commentedon Nov 4, 2025
Hi @codambro,
Indeed, junitxml currently does not report subtests.
I wonder how would we report the subtests considering the schema? https://github.com/jenkinsci/xunit-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd
pytest/src/_pytest/junitxml.py
Lines 2 to 9 in 76910ca
codambro commentedon Nov 10, 2025
Since this should be a drop-in replacement for unittest, I reviewed the unittest-xml-reporting plugin to see how it handles subtests in their JUnit XML:
I don't love their handling. They only list subtests if there is a failed one. So either:
xmlrunner README does call out that it is considered "limited support of subtests". So IMHO, this is a chance for pytest to improve, since there are open issues related to xmlrunner showing community desire for it. By reporting ALL subtests AND the parent test, pass or fail. This way reports are consistent between runs.
nicoddemus commentedon Nov 10, 2025
So if I understand correctly, it reports failed subtests as normal
testcasefailures? I guess that's the best you can do that still fits the schema.codambro commentedon Dec 2, 2025
currently, yes. I'd advocate reporting ALL subtests as normal "testcase" entries, pass or fail.
amit-gridware commentedon Jun 1, 2026
cjyhjy commentedon Oct 21, 2026
I would like to work on the JUnit XML reporting side of this. I plan to investigate separate, schema-valid testcase entries for subtests, with stable names and correct parent/subtest accounting, and add pytester coverage for passing, failing, skipped, and unittest-style subtests while keeping ordinary test output compatible.
I did not find an open PR for this issue in the linked activity or current JUnit/subtest PR search. Please let me know if someone is already implementing it or if there are naming/accounting constraints to follow. Development will use Codex assistance; the resulting patch will need human review before submission.