coroo / pytest-coverage-commentator

A Github action to comments a Pytest Coverage on PR
MIT License
45 stars 16 forks source link

Support `branch` option #167

Open keiranmraine opened 2 years ago

keiranmraine commented 2 years ago

When branch coverage is used the output isn't parsed by the headers, always assumes Stmnts, Miss, Cover.

When branch is used:

Name                  Stmts   Miss Branch BrPart     Cover
----------------------------------------------------------
src\rsm\__init__.py       0      0      0      0   100.00%
src\rsm\excel.py         80     11     28      5    85.19%
src\rsm\main.py          56      8     16      3    84.72%
src\rsm\utils.py         23      4      6      1    75.86%
----------------------------------------------------------
TOTAL                   159     23     50      9    83.73%

Required test coverage of 80.0% reached. Total coverage: 83.73%

But get:

Name Stmts Miss Cover
/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/rsm/init.py 0 0 0
/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/rsm/excel.py 80 11 28
/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/rsm/main.py 56 8 16
/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/rsm/utils.py 23 4 6
TOTAL 159 23 50
Required test coverage of

(final line relating to #98)

mfitz commented 1 year ago

Just to say, firstly, thanks for creating and open-sourcing this Github action, it's very useful, and secondly, supporting the --cov-branch flag would also be very helpful for me. We have a separate Github Actions workflow that does all of our CI checks, including a code coverage threshold check, and for that we generate the report with the pytest --cov-branch flag set.

Like @keiranmraine, I realised that using this flag breaks the table in the PR comment from pytest-coverage-commentator, so I have to leave that out when running the action. However, that means that the code coverage number in the comment disagrees with the one in our CI build, which causes some confusion:

With --cov-branch

Name                Stmts   Miss Branch BrPart  Cover
-----------------------------------------------------
aws_helper.py          35      0      2      0   100%
docker_helper.py       15      0      0      0   100%
matesto.py            123     22     28      2    79%
report_2_slack.py      64     11      8      1    81%
utils.py               54      0      0      0   100%
-----------------------------------------------------
TOTAL                 291     33     38      3    86%

Without --cov-branch

Name                Stmts   Miss  Cover
---------------------------------------
aws_helper.py          35      0   100%
docker_helper.py       15      0   100%
matesto.py            123     22    82%
report_2_slack.py      64     11    83%
utils.py               54      0   100%
---------------------------------------
TOTAL                 291     33    89%