Test Results Parser
The `test-results-parser` Python library provides functionalities to parse test result files, primarily JUnit XML. It offers two main parsing functions: `parse_junit_xml` for JUnit XML files and `parse_raw_upload` for raw test result uploads. This library is largely written in Rust with Python bindings, focusing on efficient test result processing for integration with platforms like Codecov. The current version is 0.6.1, and its release cadence appears irregular.
Warnings
- gotcha The PyPI package `test-results-parser` imports as `testing_result_parsers`. Using `import test_results_parser` will result in an `ModuleNotFoundError`.
- gotcha This library is primarily designed to parse JUnit XML files and raw test result uploads for Codecov. While it offers parsing capabilities, it's not a generic test result manipulation library like `junitparser` which supports creation and merging of XMLs.
- gotcha As a Rust-backed Python library, development setup (e.g., for contributors) requires `maturin` and a Rust toolchain.
Install
-
pip install test-results-parser
Imports
- testing_result_parsers
import testing_result_parsers
Quickstart
import testing_result_parsers
import os
# Create a dummy JUnit XML file for demonstration
dummy_junit_xml_content = '''
<testsuites>
<testsuite name="my_suite" tests="2" failures="1" errors="0" skipped="0" time="1.5">
<testcase classname="my_module.my_class" name="test_success" time="1.0" />
<testcase classname="my_module.my_class" name="test_failure" time="0.5">
<failure message="Assertion failed: 1 != 2">Traceback details...</failure>
</testcase>
</testsuite>
</testsuites>
'''
file_path = "dummy_junit.xml"
with open(file_path, "w") as f:
f.write(dummy_junit_xml_content)
# Parse the JUnit XML file
test_runs = testing_result_parsers.parse_junit_xml(file_path)
for run in test_runs:
print(f"Test Name: {run.name}, Outcome: {run.outcome}, Duration: {run.duration}")
# Clean up the dummy file
os.remove(file_path)