Strip tox path from pytest-cov output

Question:

When using pytest and pytest-cov with tox. My tox.ini is

[tox]
envlist = py3

[testenv]
deps =
    pytest
    pytest-codeblocks
    pytest-cov
commands =
    pytest {tty:--color=yes} {posargs} --cov=mypackagename

The output will contain the full tox path of the files, e.g.:

---------- coverage: platform linux, python 3.11.1-final-0 -----------
Name                                                                                     Stmts   Miss  Cover
------------------------------------------------------------------------------------------------------------
.tox/py3/lib/python3.11/site-packages/mypackagename/__init__.py                              1      0   100%
------------------------------------------------------------------------------------------------------------
TOTAL                                                                                      678    168    75%

I’m not interested in the prefix .tox/py3/lib/python3.11/site-packages/. Is there any way to remove it from the output?

mypackagename/__init__.py                                 1      0   100%
Asked By: Nico Schlömer

||

Answers:

This is expected. tox runs your tests on the installed project, not local code. Coveragepy can remap from installed to local via https://coverage.readthedocs.io/en/7.0.1/config.html#paths. See tox itself https://github.com/tox-dev/tox/blob/main/pyproject.toml#L98

Answered By: Yeti
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.