Closed nelsyeung closed 1 year ago
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.
Summary
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:
Actual result:
Reproducer
Create
src/foo/__init__.py
:Create
src/pytest_foo/__init__.py
:Create
tests/test_foo.py
:I'm using poetry for the build, so in my
pyproject.toml
I have:Run
pytest
:Versions