aconrad / pycobertura

A code coverage diff tool for Cobertura reports
MIT License
116 stars 39 forks source link

Can it help support union operation ,removing duplicate entrie #96

Closed Eldadc closed 4 years ago

Eldadc commented 4 years ago

Hi,

My goal is to merge two different coverage coberuta xml report , one was created with OpenCPPCoverage and the other with gcovr ( Code coverage by GNU GCC). The issue is that on one report some files are been covered and on the other report they are not covered , but for developers it is ok that at least on one Testing program cover a file.

We have two different cobertura xml files , One of the xml is done by cppopencoverage and one is done by gcovr. The me

How can I merge two xml as union ? I have slimier files that are on different packages, If on OpenCPPCoverage xml a file was covered 100% and on the other report generated by gcovr is 0% , The merge will not point on the 100% cover. It just add the files on different package with coverage percentage. Of course the reports are different in term of breakdown of packages.

How can I tackle such issue from your experience ? Hope you understand my question.

Thanks

aconrad commented 4 years ago

Hi @Eldadc,

Pycobertura doesn't support combining coverage reports and is meant to be a read-only cobertura report parser (not a report generator).

I'm not familiar with combining reports since I've never had to do it thus far but I know that coverage.py has a command to do that along those lines: https://coverage.readthedocs.io/en/latest/cmd.html#combining-data-files Although it's unclear to me if it could combine coverage reports from other coverage tools such as OpenCPPCoverage or gcovr...

A quick Google search for "combine cobertura reports" seems to bring up a few things and some folks have written scripts for it you might want to give a try if you haven't already.

Lastly, if you wanted to use Pycobertura, I could imagine writing some kind of merge_reports() function that could look like this:

report1 = Cobertura('cov1.xml')
report2 = Cobertura('cov2.xml')

report3 = merge_reports([report1, report2])  # not implemented
report3.write('cov3.xml')  # not implemented

... and then later use report3 as the source to generate HTML reports for example (if that is what you intend to do). But I could imagine that you'd want to make sure that both reports are generated against the same code base at the same commit version or you could get some funky results. Also, could there be intricacies in getting the proper coverage rate after combining reports?

aconrad commented 4 years ago

Closing this for now.

Eldadc commented 4 years ago

Thanks on the detailed response. Your last questions are the main requirement for the merge operation.