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

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

Open
jaredvasquez opened this issue Jan 21, 2020 · 4 comments

Comments

@jaredvasquez
Copy link

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!

@Urth
Copy link
Contributor

Urth commented Jan 23, 2020

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

@ionelmc
Copy link
Member

ionelmc commented Jan 23, 2020

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.

@MetRonnie
Copy link

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

@adithyabsk
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants