Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,27 @@ See `pytest/issues/935 <https://github.com/pytest-dev/pytest/issues/935#issuecom

**Currently there is no way to measure your pytest plugin if you use pytest-cov**.
You should change your test invocations to use ``coverage run -m pytest ...`` instead.

Warning filters can import code before coverage starts
------------------------------------------------------

Pytest resolves warning classes in ``-W`` options and ``filterwarnings``
settings during startup. If a filter names a warning class from the package
being measured, pytest imports that package before pytest-cov starts tracing.
For example::

python -m pytest --cov=mypackage -W error::mypackage.MyWarning tests/

Code executed when ``mypackage`` is first imported is not measured, even if
the tests pass. The coverage report may therefore mark import-time statements
as missing. Moving the filter into ``pytest.ini`` or ``pyproject.toml``
does not avoid the early import.

To start measurement before pytest processes its warning filters, use
coverage.py to run pytest instead::

coverage run -m pytest -W error::mypackage.MyWarning tests/
coverage report

Do not pass pytest-cov's ``--cov`` options in this invocation: the
``coverage`` command handles starting measurement and producing the report.