pytest-cov icon indicating copy to clipboard operation
pytest-cov copied to clipboard

Quick Question: Pytest-cov only works when package installed with "-e"?

Open jaredvasquez opened this issue 5 years ago • 4 comments

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!

jaredvasquez avatar Jan 21 '20 21:01 jaredvasquez

       -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.

Urth avatar Jan 23 '20 16:01 Urth

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.

ionelmc avatar Jan 23 '20 21:01 ionelmc

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.)

MetRonnie avatar Jan 24 '22 17:01 MetRonnie

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.

adithyabsk avatar Mar 04 '22 08:03 adithyabsk