pytest-cov
pytest-cov copied to clipboard
Quick Question: Pytest-cov only works when package installed with "-e"?
Hello pytest-cov developers!
I just spent an hour debugging why my coverage report was all 0% and it looks like the culprit was that my package was installed as pip install .
instead of pip install -e .
. Is that the expected behavior?
Can anyone help me to understand why the -e
option matters for the coverage report?
Thanks for your help!
-e,--editable <path/url>
Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url.
Installing in develop/editable mode creates a package.egg-link
file in the site-packages
with the directory of the source. Without this mode the source code is copied to the site-packages
.
Your coverage is configured to only check coverage of the python code from your source directory and therefore gets 0% coverage on the source code copied to site-packages
.
Please take a look at https://github.com/pytest-dev/pytest-cov/tree/master/examples - pretty sure you can copy something from there to make it work in your project.
This is why I was getting
/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/coverage/control.py:768: CoverageWarning: No data was collected. (no-data-collected)
self._warn("No data was collected.", slug="no-data-collected")
(Strangely running the doctests was generating some coverage, even though the project was not installed in editable mode.)
I was having a very similar issue. coverage run -m pytest
was producing coverage results whereas trying to use pytest-cov
was not. I had installed my package in a CI system using pip install .
instead of installing it in editable mode.