Skip to content

print python coverage results to console#331

Merged
dirk-thomas merged 2 commits intocolcon:masterfrom
mikaelarguedas:pytest-cov-console
Mar 26, 2020
Merged

print python coverage results to console#331
dirk-thomas merged 2 commits intocolcon:masterfrom
mikaelarguedas:pytest-cov-console

Conversation

@mikaelarguedas
Copy link
Contributor

Related to colcon/colcon-mixin-repository#21

no print to stderr

root@434b2f50580b:~/ws# colcon test --packages-select sros2 --pytest-with-coverage --pytest-args --cov-report=term
Starting >>> sros2   
Finished <<< sros2 [2.84s]          

Summary: 1 package finished [3.04s]

Example output in stdout:

----------- coverage: platform linux, python 3.8.2-final-0 -----------
Name                               Stmts   Miss Branch BrPart  Cover
--------------------------------------------------------------------
setup.py                              13     13      4      0     0%
sros2/__init__.py                      9      2      4      1    62%
sros2/api/__init__.py                271     58     60      8    73%
sros2/command/__init__.py              0      0      0      0   100%
sros2/command/security.py             12      2      2      1    79%
sros2/policy/__init__.py              39      5      2      1    85%
sros2/verb/__init__.py                12      2      0      0    83%
sros2/verb/create_key.py              15      3      0      0    80%
sros2/verb/create_keystore.py         14      3      0      0    79%
sros2/verb/create_permission.py       25     25      0      0     0%
sros2/verb/distribute_key.py          16     16      0      0     0%
sros2/verb/generate_artifacts.py      25     25      0      0     0%
sros2/verb/generate_policy.py         86     11     28      7    82%
sros2/verb/list_keys.py               19      3      2      1    81%
--------------------------------------------------------------------
TOTAL                                556    168    102     19    67%
Coverage HTML written to dir /root/ws/build/sros2/coverage.html
Coverage XML written to file /root/ws/build/sros2/coverage.xml

It can be less verbose by not printing all files 100% covered. It can also be made more verbose by printing line numbers of lines not covered

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
@codecov
Copy link

codecov bot commented Mar 26, 2020

Codecov Report

Merging #331 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #331   +/-   ##
=======================================
  Coverage   79.62%   79.62%           
=======================================
  Files          55       55           
  Lines        3210     3210           
  Branches      534      534           
=======================================
  Hits         2556     2556           
  Misses        607      607           
  Partials       47       47
Impacted Files Coverage Δ
colcon_core/task/python/test/pytest.py 0% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8922b7c...c1c8447. Read the comment docs.

@dirk-thomas
Copy link
Member

It can be less verbose by not printing all files 100% covered. It can also be made more verbose by printing line numbers of lines not covered

I think the current state is a good default behavior.

@dirk-thomas dirk-thomas added the enhancement New feature or request label Mar 26, 2020
@dirk-thomas
Copy link
Member

Thanks for the contribution.

@dirk-thomas dirk-thomas merged commit 4ff2203 into colcon:master Mar 26, 2020
@dirk-thomas dirk-thomas added this to the 0.5.6 milestone Mar 26, 2020
@mikaelarguedas mikaelarguedas deleted the pytest-cov-console branch March 26, 2020 22:00
@dirk-thomas
Copy link
Member

dirk-thomas commented Mar 31, 2020

@mikaelarguedas Having used this change in my daily workflow since it was merged I am not so sure anymore that enabling the output by default is such a good idea. Multiple times I ran specific tests in a package to iterate on the test result and the printed coverage information was kind of in the way. Also there was no way to avoid it being printed either.

So I am leaning towards removing the default again and instead providing a different way for users to opt-in to this (actually it should already be possible to pass --pytest-args --cov-report=term).

@mikaelarguedas
Copy link
Contributor Author

Multiple times I ran specific tests in a package to iterate on the test result and the printed coverage information was kind of in the way. Also there was no way to avoid it being printed either.

Oh interesting. All the python packages I've been testing did not declare an explicit dependency on pytest-cov so they would not do any coverage by default and only when asked to (via pytest-args or --pytest-with-coverage).
It looks like it is the case for every ROS 2 python package as well.

So I am leaning towards removing the default again and instead providing a different way for users to opt-in to this (actually it should already be possible to pass --pytest-args --cov-report=term).

That's fine by me, as long as there is an easy way to see coverage improvement locally.

Yes it can be done using pytest-args 👍
Thanks for reopening the PR on the mixin colcon/colcon-mixin-repository#22

@dirk-thomas
Copy link
Member

All the python packages I've been testing did not declare an explicit dependency on pytest-cov so they would not do any coverage by default and only when asked to

Indeed, I ran into this with e.g. colcon-core itself:

pytest-cov

dirk-thomas added a commit that referenced this pull request Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

2 participants