-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for pytest-cov branch coverage #167
Comments
Hi @kinow, can you provide some samples of what the coverage file looks like, what pycobertura reports, and what you'd like to see? I haven't worked much with branch coverage so I'm not surprised we might be lacking. |
Hi @aconrad , I will use a sample Python project as my current project is private: https://github.com/kinow/protobuf-uml-diagram But this should be the same with any Pytest project using Command-line output: ---------- coverage: platform linux, python 3.10.6-final-0 -----------
Name Stmts Miss Branch BrPart Cover
-------------------------------------------------------------
protobuf_uml_diagram.py 96 0 28 0 100.00%
-------------------------------------------------------------
TOTAL 96 0 28 0 100.00% XML: <?xml version="1.0" ?>
<coverage version="7.2.1" timestamp="1684479773746" lines-valid="96" lines-covered="96" line-rate="1" branches-valid="28" branches-covered="28" branch-rate="1" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.2.1 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/home/kinow/Development/python/workspace/protobuf-uml-diagram</source>
</sources>
<packages>
<package name="." line-rate="1" branch-rate="1" complexity="0">
<classes>
<class name="protobuf_uml_diagram.py" filename="protobuf_uml_diagram.py" complexity="0" line-rate="1" branch-rate="1">
<methods/>
<lines>
<line number="17" hits="1"/>
<line number="19" hits="1"/>
<line number="20" hits="1"/>
<line number="21" hits="1"/>
<line number="22" hits="1"/>
<line number="23" hits="1"/>
<line number="24" hits="1"/>
<line number="25" hits="1"/>
<line number="27" hits="1"/>
<line number="28" hits="1"/>
<line number="29" hits="1"/>
<line number="30" hits="1"/>
<line number="32" hits="1"/>
<line number="33" hits="1"/>
<line number="35" hits="1"/>
<line number="39" hits="1"/>
<line number="42" hits="1"/>
<line number="53" hits="1"/>
<line number="59" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="65" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="71" hits="1"/>
<line number="76" hits="1"/>
<line number="77" hits="1"/>
<line number="78" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="79" hits="1"/>
<line number="80" hits="1"/>
<line number="83" hits="1"/>
<line number="91" hits="1"/>
<line number="92" hits="1"/>
<line number="93" hits="1"/>
<line number="95" hits="1"/>
<line number="96" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="97" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="98" hits="1"/>
<line number="101" hits="1"/>
<line number="102" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="103" hits="1"/>
<line number="105" hits="1"/>
<line number="107" hits="1"/>
<line number="109" hits="1"/>
<line number="111" hits="1"/>
<line number="114" hits="1"/>
<line number="115" hits="1"/>
<line number="116" hits="1"/>
<line number="118" hits="1"/>
<line number="121" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="122" hits="1"/>
<line number="126" hits="1"/>
<line number="134" hits="1"/>
<line number="135" hits="1"/>
<line number="146" hits="1"/>
<line number="153" hits="1"/>
<line number="164" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="165" hits="1"/>
<line number="167" hits="1"/>
<line number="168" hits="1"/>
<line number="173" hits="1"/>
<line number="176" hits="1"/>
<line number="177" hits="1"/>
<line number="178" hits="1"/>
<line number="180" hits="1"/>
<line number="181" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="182" hits="1"/>
<line number="183" hits="1"/>
<line number="184" hits="1"/>
<line number="185" hits="1"/>
<line number="186" hits="1"/>
<line number="187" hits="1"/>
<line number="188" hits="1"/>
<line number="189" hits="1"/>
<line number="191" hits="1"/>
<line number="192" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="193" hits="1"/>
<line number="194" hits="1"/>
<line number="195" hits="1"/>
<line number="196" hits="1"/>
<line number="198" hits="1"/>
<line number="199" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="200" hits="1"/>
<line number="201" hits="1"/>
<line number="202" hits="1"/>
<line number="204" hits="1"/>
<line number="205" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="206" hits="1"/>
<line number="207" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="208" hits="1"/>
<line number="209" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="210" hits="1"/>
<line number="212" hits="1"/>
<line number="218" hits="1"/>
<line number="219" hits="1"/>
<line number="220" hits="1"/>
<line number="222" hits="1"/>
<line number="227" hits="1"/>
<line number="228" hits="1"/>
<line number="230" hits="1"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage> And screenshot of the HTML report: |
Interesting, thanks for sharing @kinow. I didn't know about the |
Sure, here's another project I worked on some time ago that also uses coverage.xml in this gist https://gist.github.com/kinow/328f7313756022694638bca296aff4dd |
FWIW I remember reading about how they calculate the coverage when branching is enabled (IIRC, because SonarQube was giving a different line & branch coverage?), and it was not very straightforward. But hopefully it's not too complicated and can be added to pycobertura. |
I see a few tasks here:
Would someone want to take a stab at it? Happy to review this work in smaller PRs so it's not too big to review and is more incremental. Anyone? |
Trying to take a stab at this... |
In the summary table, when listing missing lines, does it make sense if we count partial lines as missed? I'm not sure I want to introduce a "partial" column, I don't think it has much relevance to us. Thoughts? |
Good question, @aconrad . I replaced However, as soon as I updated the GH Action to comment I couldn't find a solution as to where/how to add it to the existing table… so at the moment the GH bot creates a comment with the report extracted from I am not sure if that would be practical for projects with many files. It works for us for now as we have about 10-20 files. Maybe just rename or document that column as "Missing lines", and show that column next to the part about line coverage? Thanks! |
Another thing noteworthy about the partially hit for-loop: the |
Hi,
Thanks a lot for
pycobertura
. I used it to automate the coverage reporting of an internal project. Since we are using a private GitHub repository, we used GitHub actions to run the coverage and add a comment with the Markdown produced bypycobertura
.However, today I noticed that we have
--cov-branch
enabled, and the reported values in the output ofpycobertura
do not match what's displayed in the cmd-line & HTML reports of pytest-cov.Would it be possible to match that somehow? Maybe adding a new flag, and maybe calling the pytest-cov (as they seem to have a special way to calculate the coverage when using branches).
Thanks!
The text was updated successfully, but these errors were encountered: