Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ Authors
* Markéta Machová - https://github.com/MeggyCal
* xuu33030 - https://github.com/xuu33030
* dly - https://github.com/xlyy1
* Jean-Francois Paquin - https://github.com/jf-paquin-web
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Unreleased
from a subdirectory no longer ignores the project's ``pyproject.toml`` /
``setup.cfg`` / ``tox.ini`` / ``.coveragerc``.
See `#692 <https://github.com/pytest-dev/pytest-cov/issues/692>`_.
* Fixed xdist workers leaving a stray coverage collector running (started because workers inherit the master's ``-n`` option).
It got resumed whenever the worker's coverage was paused, so ``no_cover`` tests still ran under a tracer.

7.1.0 (2026-03-21)
------------------
Expand Down
5 changes: 5 additions & 0 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ def pytest_sessionstart(self, session):

self.pid = os.getpid()
if self._is_worker(session):
if self.cov_controller is not None:
# xdist builds the worker config from the master's args (it resets numprocesses only afterwards),
# so __init__ has already started a DistMaster here. Stop it or it would be left on coverage's
# collector stack and get resumed whenever the worker's coverage is paused (eg: no_cover).
self.cov_controller.cov.stop()
nodeid = session.config.workerinput.get('workerid', session.nodeid)
self.start(engine.DistWorker, session.config, nodeid)
elif not self._started:
Expand Down
25 changes: 25 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,31 @@ def test_basic():
result.stdout.fnmatch_lines(['mod* 2 * 1 * 50% * 2'])


@xdist_params
def test_no_cover_marker_stops_tracing(testdir, opts):
script = testdir.makepyfile(
"""
import pytest
from coverage.collector import Collector

def record(name):
with open(name + '.txt', 'w') as fh:
fh.write(str(len(Collector._collectors)))

def test_normal():
record('normal')

@pytest.mark.no_cover
def test_no_cover():
record('no_cover')
"""
)
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script, *opts.split())
assert result.ret == 0
assert testdir.tmpdir.join('normal.txt').read() == '1'
assert testdir.tmpdir.join('no_cover.txt').read() == '0'


def test_no_cover_marker_with_no_cov(testdir):
script = testdir.makepyfile(
"""
Expand Down