Skip to content

Failure to capture correct coverage of pytest plugin #372

Closed

Description

@adamtheturtle

My use case

  • I am developing a new pytest plugin, and am a happy user of pytest-cov in 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 pytest11 entry 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 == 10

new_plugin_package/my_plugin.py

import pytest

@pytest.fixture()
def new_fixture() -> int:
    return 10

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

Activity

  1. ionelmc commented on Jan 12, 2020

    @ionelmc
    Member
  2. adamtheturtle commented on Jan 14, 2020

    @adamtheturtle
    Author

    Thank you @ionelmc - that solved my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions