coveragepy
coveragepy copied to clipboard
Option to use relative file paths in report
Is your feature request related to a problem? Please describe.
The new relative_files
config options toggle whether relative paths are stored in the data files, and also how they're reported in XML reports. However, file paths are still absolute in the CLI report (i.e. the one shown with coverage report
).
Describe the solution you'd like
A possibility to have the CLI report respect relative_files
and show relative paths, either by default or through a toggle.
Describe alternatives you've considered
Using sed
to remove the prefix in reported file paths.
Additional context Related issue: #948.
Also: thanks for the great package!
I think this issue describes the problem I am having too. I reached for relative_files
but it didn't solve my problem. For $reasons, our build system wants to run coverage (through pytest) in a different directory, against the the installed site-packages
location of our code inside a venv. While I'm not super happy about that, I can't change it. But this leads to ugly and useless absolute paths in the coverage console report:
---------- coverage: platform darwin, python 3.7.7-final-0 -----------
Name Stmts Miss Branch BrPart Cover Missing
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/Users/bwarsaw/projects/xx/xxxx-xxxxxxx_trunk/build/xxxx-xxxxxxx/environments/satellites/project/lib/python3.7/site-packages/xxxxxxxx/xxxxxxx/__init__.py 0 0 0 0 100%
/Users/bwarsaw/projects/xx/xxxx-xxxxxxx_trunk/build/xxxx-xxxxxxx/environments/satellites/project/lib/python3.7/site-packages/xxxxxxxx/xxxxxxx/constants.py 19 0 0 0 100%
/Users/bwarsaw/projects/xx/xxxx-xxxxxxx_trunk/build/xxxx-xxxxxxx/environments/satellites/project/lib/python3.7/site-packages/xxxxxxxx/xxxxxxx/exception.py 5 0 0 0 100%
/Users/bwarsaw/projects/xx/xxxx-xxxxxxx_trunk/build/xxxx-xxxxxxx/environments/satellites/project/lib/python3.7/site-packages/xxxxxxxx/xxxxxxx/xxxxxxx.py 67 10 36 7 82% 89->90, 90, 101->102, 102, 115->121, 134->135, 135, 137->161, 141->142, 142, 144->145, 145, 161-162, 168-171
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL 91 10 36 7 85%
I would love to find a way to chop off everything left of and including the site-packages
component.
This problem also happened in the html report
See also #277.
Is it enough to use the relative file as stored?
I think so. But where are they stored? I cannot find any relative paths in the data file. I'm running 6.1.1 on Python 3.10.0 via
$ MY_DIR=$(pwd)
$ cd /tmp
$ PYTHONPATH=$MY_DIR coverage run --rcfile=$MY_DIR/.coveragerc --source=$MY_DIR -m pytest $MY_DIR/tests
with relative_files = True
in .coveragerc
. Am I overlooking something?
Would this account for src
-layout structures? I would like src/pkg
to become just pkg
.
As others have already noted, this applies to the html
report type as well as the command line report. It also applies to the lcov
report, which is important for integrating into bazel (to avoid needing this hack). I do believe from my experimentation that the relative file as stored is good enough there.