aconrad / pycobertura

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

Support parsing(ignoring) method info #118

Open CurryPseudo opened 2 years ago

CurryPseudo commented 2 years ago

Currently, pycobertura only accepet

<class><lines>...<lines><class>

But there are some cobertura outputs contain method infos like

<class><methods><method><lines>...<lines></method></methods></class>

The input like above will make pycobertura simply reporting error:

Invalid coverage file: ...

Could we just ignore the methods info?

aconrad commented 2 years ago

Hi, thanks for raising this.

Do the <methods> tags provide any relevant line coverage information? If we ignore them, would we miss anything?

I don't have much time to make changes to pycobertura but I'll happily review pull requests if you want to suggest a change.

aconrad commented 2 years ago

Can you provide a sample coverage file that is causing this issue?

CurryPseudo commented 2 years ago

OK~ Here is a sample coverage file from a rust library, generated by https://github.com/mozilla/grcov https://github.com/CurryPseudo/rust-coverage/blob/main/cobertura.xml

aconrad commented 2 years ago

OK~ Here is a sample coverage file from a rust library, generated by https://github.com/mozilla/grcov https://github.com/CurryPseudo/rust-coverage/blob/main/cobertura.xml

Thanks for sharing a coverage file. As far as I can tell, the lines under the xpath //coverage/packages/classes/class/methods are redundant with the ones under //coverage/packages/classes/class/lines so I don't think we're missing any per-line coverage data by only parsing the latter.

I ran pycobertura show against the cobertura.xml file you pointed me to, and it works fine:

pycobertura show issue-118.xml
Filename      Stmts    Miss  Cover    Missing
----------  -------  ------  -------  ---------
src/lib.rs       11       1  90.91%   14
TOTAL            11       1  90.91%

Can you share how you are getting the error Invalid coverage file: ...?