xunitparserx
raw JSON → 1.9.12 verified Fri May 01 auth: no python
Read JUnit/XUnit/MSTest XML files and map them to Python objects. Current version 1.9.12, released irregularly.
pip install xunitparserx Common errors
error ImportError: No module named xunitparserx ↓
cause Package not installed or environment missing.
fix
Run 'pip install xunitparserx'.
error AttributeError: 'str' object has no attribute 'iterparse' ↓
cause Passing a file path string instead of a file object to parse().
fix
Open the file first: with open('file.xml') as f: suite, report = parse(f)
Warnings
gotcha The parse function returns a tuple (suite, report). The 'report' object may be None if not parsing a report-style XML. ↓
fix Always accept both: suite, report = parse(...). Check report for None if needed.
gotcha The library expects well-formed XML per JUnit/XUnit schema. Malformed or non-standard XML may cause parse errors or missing attributes. ↓
fix Validate XML against the schema before parsing. Use lxml or xml.etree for pre-validation.
deprecated Older versions used methodnames like 'test.classname' and 'test.methodname'; these have been replaced by 'test.classname' and 'test.methodname' (same). Check if your version uses 'test.classname' or 'test.classname'. ↓
fix Use 'test.classname' and 'test.methodname' (they remain consistent).
Imports
- parse
from xunitparserx import parse - TestSuite
from xunitparserx import TestSuite
Quickstart
from xunitparserx import parse
# Parse an XUnit XML file
with open('results.xml', 'r') as f:
suite, report = parse(f)
# Access test suite info
print(f"Tests: {suite.tests}, Failures: {suite.failures}, Errors: {suite.errors}")
# Iterate over test cases
for test in suite.test_cases():
print(f"{test.classname}.{test.methodname}: {test.result}")