Skip to main content

junit-merge

One JUnit XML file from many, with counts you can trust.

python -m junit_merge check-reports/*.xml --out junit.xml
from junit_merge import merge_files

report = merge_files(["shard-1.xml", "shard-2.xml"], "junit.xml")
print(report.tests, report.failures)

Sharded CI jobs, pytest --junitxml per matrix leg and retried flaky tests all leave you with several reports when the dashboard wants one. Concatenating the XML is invalid, and adding up each file's tests and failures attributes double counts every test a shard re-ran.

This package parses the reports, rebuilds the merged document from the test cases themselves, and recomputes every count, so the numbers always match the contents.

Duplicate tests

A test that appears in more than one report (the usual result of a retry) is resolved with on_duplicate:

policy behaviour
keep-worst (default) keep the failure or error over the pass; a test that failed anywhere stays failed
keep-first keep the first occurrence
keep-last keep the last occurrence
keep-both keep every occurrence
fail raise, naming the test, instead of guessing

Keeping the worst outcome is the safe default: a flaky retry cannot hide a real failure from the report.

Install

pip install junit-merge

API

from junit_merge import merge, merge_files, parse, parse_file, to_xml

report = parse_file("shard-1.xml")  # Report
merged = merge([report, parse_file("shard-2.xml")], on_duplicate="keep-worst")
merged.tests, merged.failures, merged.errors, merged.skipped, merged.time
data = to_xml(merged)  # bytes, valid <testsuites> document

parse accepts str, bytes, a path is handled by parse_file, and a document name-spaced by tools like Jenkins is understood. Invalid XML raises ValueError with the reason, not a bare ParseError.

What is preserved

  • classname, name, time, file, line
  • <failure>, <error> and <skipped> including message and the text body
  • <system-out> and <system-err>
  • suite <properties>, first value winning on a clash

Cases are sorted by class and name by default, so two runs of the same merge produce identical bytes; pass sort=False to keep the input order.

What is not

  • It does not run tests, retry them or upload anything: it merges files.
  • Attributes nobody sets from test cases (timestamp, hostname) are not invented.
  • A report whose contents contradict each other is trusted on the cases, which is the only part that can be verified.

Development

python -m venv .venv
.venv/bin/pip install -e ".[test]"
.venv/bin/pytest

License

MIT.

Metadata

Release files for junit-merge 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for junit-merge 0.1.0
File Size Uploaded Provenance Actions
junit_merge-0.1.0.tar.gz 10.5 kB Without provenance Details for junit_merge-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for junit-merge 0.1.0
File Interpreter ABI Platform Actions
junit_merge-0.1.0-py3-none-any.whl Python 3 none any Details for junit_merge-0.1.0-py3-none-any.whl

Total release size: 18.6 kB

Release files / junit_merge-0.1.0.tar.gz

Download URL junit_merge-0.1.0.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f1466076df100d93eef95dd60d6a3b2b90d1c6704be9176efc1972b1991a45b9
BLAKE2b-256 checksum
How to use checksums
c1f423183d66a7db0048d8cf18163c76dc90f432d5536cb7d02c2e20c69234f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / junit_merge-0.1.0-py3-none-any.whl

Download URL junit_merge-0.1.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97793a06ab869c3bffaf0a1c926d7211e934b7eb9090c7ea303e03d9d9fb021b
BLAKE2b-256 checksum
How to use checksums
e3eb534cec9f652846c6c0d2fedd8d61773b67ba5a75447b19e5a45ca3eea732
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for junit-merge 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page