Skip to content
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

Option to use relative file paths in report #963

Open
teake opened this issue Mar 24, 2020 · 8 comments
Open

Option to use relative file paths in report #963

teake opened this issue Mar 24, 2020 · 8 comments
Labels
enhancement New feature or request next

Comments

@teake
Copy link
Contributor

teake commented Mar 24, 2020

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.

@teake teake added the enhancement New feature or request label Mar 24, 2020
@teake
Copy link
Contributor Author

teake commented Mar 24, 2020

Also: thanks for the great package!

@warsaw
Copy link

warsaw commented Jun 4, 2020

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.

@cnzhujie
Copy link

This problem also happened in the html report

@nedbat nedbat added this to the 5.1 milestone Jul 13, 2020
@nedbat nedbat modified the milestones: 5.next, 6.0 Jun 3, 2021
archlinux-github pushed a commit to archlinux/archlinux-keyring that referenced this issue Nov 1, 2021
pyproject.toml:
Set specific source for `toolscoverage.paths` (as we only provide one
module).
Set `tools.coverage.run.relative_files` to true (although it is still
bug riddled and does not seem to work as advertized in regards to xml
output: nedbat/coveragepy#963,
nedbat/coveragepy#1147).
Set `tool.coverage.xml.output`, so we don't have to provide it on the
commandline.

Makefile:
Do not provide an output file to the coverage xml call, as we do that in
configuration now.
@nedbat
Copy link
Owner

nedbat commented Nov 6, 2021

See also #277.

@nedbat
Copy link
Owner

nedbat commented Nov 6, 2021

Is it enough to use the relative file as stored?

@teake
Copy link
Contributor Author

teake commented Nov 8, 2021

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?

@nedbat nedbat added the next label Nov 13, 2021
@nedbat nedbat removed this from the Next milestone Nov 13, 2021
archlinux-github pushed a commit to archlinux/archlinux-keyring that referenced this issue Nov 30, 2021
pyproject.toml:
Set specific source for `toolscoverage.paths` (as we only provide one
module).
Set `tools.coverage.run.relative_files` to true (although it is still
bug riddled and does not seem to work as advertized in regards to xml
output: nedbat/coveragepy#963,
nedbat/coveragepy#1147).
Set `tool.coverage.xml.output`, so we don't have to provide it on the
commandline.

Makefile:
Do not provide an output file to the coverage xml call, as we do that in
configuration now.
archlinux-github pushed a commit to archlinux/archlinux-keyring that referenced this issue Nov 30, 2021
pyproject.toml:
Set specific source for `toolscoverage.paths` (as we only provide one
module).
Set `tools.coverage.run.relative_files` to true (although it is still
bug riddled and does not seem to work as advertized in regards to xml
output: nedbat/coveragepy#963,
nedbat/coveragepy#1147).
Set `tool.coverage.xml.output`, so we don't have to provide it on the
commandline.

Makefile:
Do not provide an output file to the coverage xml call, as we do that in
configuration now.
@ofek
Copy link

ofek commented Jan 2, 2022

Would this account for src-layout structures? I would like src/pkg to become just pkg.

@adam-azarchs
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request next
Projects
None yet
Development

No branches or pull requests

6 participants