pycobertura
pycobertura copied to clipboard
Support for merge cobertura.xml files.
Hello,
the functionality that will allow to merge many cobertura files would be great. This problem is common:
https://stackoverflow.com/questions/64370596/can-i-combine-mypy-reports-with-pytest-coverage-reports https://stackoverflow.com/questions/26469072/is-there-anyway-to-merge-cobertura-coverage-xml-reports-together
And there is even a npm module that solves it, but it will need to install whole node on python based Docker image to use it. https://www.npmjs.com/package/cobertura-merge
What do you think about it??
Hi @marwin1991 What are the exact rules for merging, if I know them, then I can implement it :)
That sounds like a whole new utility to me. Such as pycobertura merge
...
I guess the logic is:
- if coverage1.xml has line
<line filename="foo" hits="0">
and coverage2.xml has<line filename="foo" hits="1">
then the resulting merge would have<line filename="foo" hits="1">
. - coverage rates should get recomputed based on the new total number of lines in the merged report.
- I think we'd probably want to have the ability to merge 2 Cobertura files that aren't part of the same code base or that have no file paths in common, e.g. the same code base could host C files and Ruby files but the report from each language will generate 2 very different coverage reports.
Great idea! IMO the most common example is when you have f.e. JS in frontend and Java/Python/Ruby in backend. When it comes to visualise the result in GitLab you need one file
@marwin1991 Could provide exemplary test input files and a test output file? I think this would be most helpful...
Hello, here I have a simple cobertura.xml for spring boot java project: cobertura.xml.txt
I will try to get some example of JS like React or Angular :)
Hi @marwin1991 Thanks, would be good if you could also provide the wished output file with the 2 input files you provide :) Also from your example, I assume that this is also relevant for you: https://github.com/aconrad/pycobertura/issues/118.
Hi @aconrad @marwin1991
Regarding the implementation of the merge
command, there are the following steps in my view:
- Parsing the input xml files (could be an arbitrary number) and extract the statistics.
- Merge the statistics using a merge function
- Write the statistics in an output xml file (whose name is also given on the command line, would be the last parameter).4.
Am I correct?
And @aconrad: What do we already have for the first part?
For 1. I think we have most of it implemented, pycobertura is first a cobertura parser.
I believe that coveragepy has a functionality to merge/combine coverage reports. Is this relevant to us? https://coverage.readthedocs.io/en/stable/cmd.html#cmd-combine
Could users use that before using pycobertura? If yes, then maybe we don't need to implement this feature, although I'm not against it either. We just need to consider what our options are. Thoughts?
@marwin1991 Can you explain why coverage combine
does not satisfy your needs or why the integration into pycobertura
would be extremely helpful? - see also the link by @aconrad above: https://coverage.readthedocs.io/en/stable/cmd.html#cmd-combine.
As far as I can tell, coverage combine
doesn't merge XML cobertura files.
As far as I can tell,
coverage combine
doesn't merge XML cobertura files.
Hm, I think you're right. It might only combine coverage data generated by coverage.py but not take other formats as input.
I'd be okay to introduce a pycobertura merge
command. Although I don't have much time to work on it so PRs are welcome.
I needed to do this as a one-off, and I tweaked this script as a basis: https://github.com/janhybs/Flow123d-python-utils/blob/master/src/coverage/coverage_merge_module.py
This is what I ended up doing on Home Assistant (they split tests into 10 groups so they can run on separate VM):
Step 1 => download 10 zip artifacts from github
Step 2 => extract the 10 xml files from the 10 zip files
Step 3 => use the script above to merge the 10 xml files
Step 4 => run a custom script to "fix" the line-rate
as the script kept the original values
Step 5 => run pycobertura show to display the result
I needed to do this as a one-off, and I tweaked this script as a basis: https://github.com/janhybs/Flow123d-python-utils/blob/master/src/coverage/coverage_merge_module.py
This is what I ended up doing on Home Assistant (they split tests into 10 groups so they can run on separate VM): Step 1 => download 10 zip artifacts from github Step 2 => extract the 10 xml files from the 10 zip files Step 3 => use the script above to merge the 10 xml files Step 4 => run a custom script to "fix" the
line-rate
as the script kept the original values Step 5 => run pycobertura show to display the result
Could please upload the input xml files and the output xml file somewhere.
Sadly I have managed to loose my merge script, my input files and my output file in a messed up GIT rebase.
You can download some fresh input XML files from https://github.com/home-assistant/core/actions/runs/4161973175 (see the 12 artifacts at the bottom)