Skip to content

Subcommand to merge coverage files#200

Open
drhagen wants to merge 13 commits into
aconrad:masterfrom
drhagen:merge-coverage
Open

Subcommand to merge coverage files#200
drhagen wants to merge 13 commits into
aconrad:masterfrom
drhagen:merge-coverage

Conversation

@drhagen

@drhagen drhagen commented Jun 20, 2026

Copy link
Copy Markdown

This implements #119 by adding the pycobertura merge command. It works basically how you would expect. The command takes multiple files and loops over each one, summing the hits across all the matching lines.

There is a --output option that lets the user specify an output file. Otherwise, it goes to stdout like elsewhere in pycobertura.

There is a --source option that takes a glob-like path to be stripped from the filenames within the XML files. I would expect something like --source '**/site-packages/' would be useful for coverage.py output.

it also supports --ignore-regex, but mainly because pycobertura supports that everywhere else. I'm not sure its that useful here.

After summing, the line-rate, lines-valid, lines-covered, branch-rate, branches-valid, and branches-covered attributes are recomputed. There are other attributes in Cobertura files that I don't think anyone cares about, but this implementation tries to handle them as sensibly as it can.

  • condition-coverage: There is no way to tell if 1/2 and 1/2 branches covered were disjoint or overlapping, so I take the maximum of the numerator and the maximum of the denominator.
  • complexity: Nothing to do except take the max when merging.
  • version: This contains pycobertura {version}

This feature was implemented using spec driven development with the assitance of AI. The spec can be found as the file deleted in the last commit. This spec was reviewed carefully by a human throughout the process. The code and tests were generated from the spec. The AI was prompted repeatedly to check the implementation against the spec, the tests against the spec, and the code style against the rest of pycobertura. Finally, I reviewed the final code and tests, making manual changes where prudent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant