You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong coverage when there's a pytest plugin installed that imports the module that you want to cover #587
When there's a pytest plugin installed that imports the module that you want to have coverage, it will not cover that module. However, running coverage run -m pytest ... works as expected.
Expected vs actual result
Expected:
src/foo/__init__.py 2 0 100%
Actual result:
src/foo/__init__.py 2 1 50%
Reproducer
Create src/foo/__init__.py:
deffoo() ->str:
return"foo"
Create src/pytest_foo/__init__.py:
importfoo
Create tests/test_foo.py:
importfoodeftest_foo():
assertfoo.foo() =="foo"
I'm using poetry for the build, so in my pyproject.toml I have:
tests/test_foo.py . [100%]
---------- coverage: platform darwin, python 3.7.13-final-0 ----------
Name Stmts Miss Cover
-----------------------------------------
src/foo/__init__.py 2 1 50%
-----------------------------------------
TOTAL 2 1 50%
FAIL Required test coverage of 80% not reached. Total coverage: 50.00%
I realised that although this is a slightly different problem than https://pytest-cov.readthedocs.io/en/latest/plugins.html (since I'm not even trying to cover the plugin itself just the API it uses separately), it's probably caused by the same underlying problem with the plugin system. As a workaround, I wrote a script that generates a .pth file and put it into the site-packages directory which sets the coverage variables when running pytest.
Activity
nelsyeung commentedon Mar 16, 2023
I realised that although this is a slightly different problem than https://pytest-cov.readthedocs.io/en/latest/plugins.html (since I'm not even trying to cover the plugin itself just the API it uses separately), it's probably caused by the same underlying problem with the plugin system. As a workaround, I wrote a script that generates a
.pthfile and put it into thesite-packagesdirectory which sets the coverage variables when running pytest.webknjaz commentedon Dec 21, 2025
Try
-p pytest_cov