Skip to content

Incorrect coverage reporting for pytest plugins #439

Closed

Description

@bbonenfant

Summary

When I used the pytest-cov plugin to report coverage on a pytest plugin, I receive an incorrect coverage report. I am using the poetry package manager (I'm not sure if that is relevant) and marking the package as a plugin using the tool.poetry.plugins.pytest11 section of my pyproject.toml. If I remove this section, the package is no longer a plugin and I receive the expected coverage report.

Reproducer

Versions

Relevant Versions

pytest       6.1.1
pytest-cov   2.10.1
python       3.6.5
poetry       1.0.10

All Packages

attrs              20.2.0
coverage           5.3
importlib-metadata 2.0.0
iniconfig          1.0.1
packaging          20.4
pluggy             0.13.1
py                 1.9.0
pyparsing          2.4.7
pytest             6.1.1
pytest-cov         2.10.1
six                1.15.0
toml               0.10.1
zipp               3.3.0

Config

pyproject.toml:

[tool.poetry]
name = "bug_report"
version = "0.1.0"
description = ""
authors = ["John Smith <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.6"

[tool.poetry.dev-dependencies]
pytest = "^6.1.1"
pytest-cov = "^2.10.1"

[tool.poetry.plugins.pytest11]
example = "bug_report.plugin"

[build-system]
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"

Code

Directory structure:

\
 | - bug_report
 |     | - plugin.py
 | - pyproject.toml
 | - test_plugin.py

bug_report:

def example_func():
    return True

test_plugin.py:

from bug_report.plugin import example_func

def test_example_func():
    assert example_func()

Command

pytest --cov=bug_report --cov-fail-under=100 --cov-report=term-missing

Output

Note that if you are going to reproduce using poetry, you need to run poetry install after adding or removing the tool.poetry.plugins.pytest11 section from the pyproject.toml file.

Expected

(without the tool.poetry.plugins.pytest11 section of the pyproject.toml file)

======================== test session starts =========================
platform darwin -- Python 3.6.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: /Users/bbonenfant/PycharmProjects/pytest-cov-bug
plugins: cov-2.10.1
collected 1 item

test_plugin.py .                                               [100%]

---------- coverage: platform darwin, python 3.6.5-final-0 -----------
Name                   Stmts   Miss  Cover   Missing
----------------------------------------------------
bug_report/plugin.py       2      0   100%

Required test coverage of 100% reached. Total coverage: 100.00%

========================= 1 passed in 0.05s ==========================

Result

(with the tool.poetry.plugins.pytest11 section of the pyproject.toml file)

========================= test session starts =========================
platform darwin -- Python 3.6.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: /Users/bbonenfant/PycharmProjects/pytest-cov-bug
plugins: cov-2.10.1, bug-report-0.1.0
collected 1 item

test_plugin.py .                                                [100%]

---------- coverage: platform darwin, python 3.6.5-final-0 -----------
Name                   Stmts   Miss  Cover   Missing
----------------------------------------------------
bug_report/plugin.py       2      1    50%   1

FAIL Required test coverage of 100% not reached. Total coverage: 50.00%

========================== 1 passed in 0.05s ==========================

Activity

  1. ionelmc commented on Oct 4, 2020

    @ionelmc
    Member
  2. bbonenfant commented on Oct 4, 2020

    @bbonenfant
    Author

    Ahh, my apologies, I spent a lot of time searching and somehow never can across this documentation. Thank you!

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