coveragepy
coveragepy copied to clipboard
Coverage fails to work on installed modules
Describe the bug coverage tool fails to identify any source files in installed modules.
To Reproduce How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:
- What version of Python are you using? 3.10.10
- What version of coverage.py shows the problem? 7.2.3
- What versions of what packages do you have installed? coverage==7.2.3 ONLY
- What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix. https://github.com/EnnFour/coverage-example
- What commands did you run?
First, create and activate a clean virtual environment
python3.10 -m venv venv; source venv/bin/activate
. Next, install the package withcd python; python setup.py install
Finally, run the coverage tool.
cd src/coolpkg
coverage run -m unittest discover -s ../../tests
coverage report
yields
Name Stmts Miss Cover
---------------------------------------------------------------------
/coverage-example/python/tests/test_coolpkg.py 5 0 100%
---------------------------------------------------------------------
TOTAL 5 0 100%
Expected behavior I expected the report to show 4 statements, 2 of which were covered, in the file /coverage-example/python/src/coolpkg/core/code.py.
Additional context
Running the coverage command coverage run -m unittest discover
from the python directory shows a report only with files from the tests directory.
Using the debug=trace flag, we see that
/venv-test/lib/python3.10/site-packages/coolpkg-1.0.0-py3.10.egg/coolpkg/core/code.py': is a third-party module
This is motivation for the use of --source=/venv-test/lib/python3.10/site-packages/coolpkg-1.0.0-py3.10.egg/coolpkg/*, but this also does not work. Also, kinda painful if I'd need to specify the version number every time.
I'd like the file structure to remain the same as it is (the tests are outside the actual installed module).