junit-merge
junit-merge

how junit-merge fits in

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-firstkeep the first occurrence
keep-lastkeep the last occurrence
keep-bothkeep every occurrence
failraise, 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

consolepip install junit-merge

API

pythonfrom 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

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

the only part that can be verified.

Development

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

The suite covers every line of the package (pytest --cov --cov-branch), and the examples in the docstrings run as tests through --doctest-modules.

License

MIT.

Other libraries here

One problem each, standard library only, no runtime dependencies.