Repository navigation
Closed
Description
My use case
- I am developing a new pytest plugin, and am a happy user of
pytest-covin many projects (:pray:). - I wish to enforce 100% line coverage for the plugin, and measure this with
pytest-cov. - Problem: import lines and function definition lines are not counted for a file which is a
pytest11entry point. I believe that this is a bug but maybe I need some different configuration?
Small sample reproducer
Files for reproducer
.
├── new_plugin_package
│ └── my_plugin.py
├── setup.py
└── tests
└── test_example.py
setup.py
from setuptools import setup
setup(
packages=['new_plugin_package'],
install_requires=['pytest', 'pytest-cov'],
entry_points={'pytest11': ['new_plugin = new_plugin_package.my_plugin']},
)tests/test_example.py
def test_new_fixture(new_fixture: int) -> None:
assert new_fixture == 10new_plugin_package/my_plugin.py
import pytest
@pytest.fixture()
def new_fixture() -> int:
return 10Error reproduction
# In a Python 3.7 virtualenv
$ pip install --editable .
...
$ pytest --cov tests/ --cov new_plugin_package/ --cov-report term-missing
============================================================================================= test session starts ==============================================================================================
platform darwin -- Python 3.7.5, pytest-5.3.1, py-1.8.0, pluggy-0.13.1
rootdir: /Users/adam/Desktop/pytest-cov-example
plugins: cov-2.8.1, UNKNOWN-0.0.0
collected 1 item
tests/test_example.py . [100%]
---------- coverage: platform darwin, python 3.7.5-final-0 -----------
Name Stmts Miss Cover Missing
---------------------------------------------------------------
new_plugin_package/my_plugin.py 4 3 25% 1-4
tests/test_example.py 2 0 100%
---------------------------------------------------------------
TOTAL 6 3 50%
============================================================================================== 1 passed in 0.03s ===============================================================================================
Expectation: Both files show 100% coverage.
Metadata
Metadata
Assignees
Labels
No labels
Activity
ionelmc commentedon Jan 12, 2020
Recording pytest plugin coverage is tricky business, see https://pytest-cov.readthedocs.io/en/latest/plugins.html
adamtheturtle commentedon Jan 14, 2020
Thank you @ionelmc - that solved my issue.