xunitparser
raw JSON → 1.3.4 verified Mon Apr 27 auth: no python
Read JUnit/XUnit XML files and map them to Python objects. Current version is 1.3.4, with infrequent releases.
pip install xunitparser Common errors
error AttributeError: 'NoneType' object has no attribute 'name' ↓
cause parse() returned None for testsuite when the XML could not be parsed, or the file was empty.
fix
Check that the XML file is valid and contains a <testsuite> element. Wrap parse in try-except.
error TypeError: 'module' object is not callable ↓
cause Using 'xunitparser.parse()' without importing the parse function correctly.
fix
Use: from xunitparser import parse
Warnings
gotcha The parse() function returns two values: (testsuite, testresult). The testresult object is often ignored but contains overall counts. Many users forget to unpack both. ↓
fix Always unpack both: ts, tr = parse(f) even if you don't use tr.
gotcha The library only handles JUnit XML format. Variants from pytest (--junitxml) or other runners may produce slightly different XML that fails to parse. ↓
fix Ensure the XML file is standard JUnit format. For pytest output, use 'pytest --junitxml=report.xml' and note that xunitparser handles it well.
deprecated The library has not been updated since 2018. It uses ancient Python idioms and may not support Python 3.10+ fully (though it still works). ↓
fix Consider alternatives like junitparser or junit-xml if you need active maintenance.
Imports
- parse wrong
import xunitparser; ts, tr = xunitparser.parse(open('file.xml'))correctfrom xunitparser import parse - XmlTestSuite
from xunitparser import XmlTestSuite
Quickstart
from xunitparser import parse
import sys
with open('test-results.xml') as f:
ts, tr = parse(f)
print(f'Testsuite: {ts.name}, tests: {ts.tests}, failures: {ts.failures}, errors: {ts.errors}')
for tc in ts:
print(f' Testcase: {tc.methodname} - {tc.result}')