Skip to content

fix: stop stray DistMaster coverage in xdist worker - #771

Open
jf-paquin-web wants to merge 1 commit into
pytest-dev:masterfrom
jf-paquin-web:fix/xdist-worker-double-coverage
Open

jf-paquin-web wants to merge 1 commit into
pytest-dev:masterfrom
jf-paquin-web:fix/xdist-worker-double-coverage

Conversation

@jf-paquin-web

@jf-paquin-web jf-paquin-web commented Oct 29, 2026 •

Copy link
Copy Markdown

Summary

xdist workers start with a copy of the master's args, so -n is still set when CovPlugin.__init__ runs in a worker. As a result, each worker started a DistMaster, then started a DistWorker on top of it without stopping the first one. Two collectors ended up on coverage's stack. Pausing the worker's coverage for no_cover brought the stray tracer back, so no_cover tests were still traced under xdist.

 worker: _prepareconfig(master args, -n still set)
   CovPlugin.__init__
     start(DistMaster)              # stray: erase() + cov.start()
 worker: pytest_sessionstart
+  cov_controller.cov.stop()        # pop the stray collector
   start(DistWorker)

Evidence

New test test_no_cover_marker_stops_tracing (nodist / 1xdist / 2xdist / 3xdist). Each inner test records how many collectors are active and whether a tracer is set:

  • Before: 3 failed, 1 passed. In workers, the normal test saw collectors=2 and the no_cover test still had a tracer.
    After: 4 passed. Normal test: collectors=1. no_cover test: collectors=0, sys.gettrace() is None.

Full tox run (pytest 9.0.2, xdist 3.8.0, coverage 7.13.5):

Env Result
py310, py311, py312, py313, py314, py315 218 passed, 4 skipped
pypy310, pypy311 216 passed, 6 skipped
check (build, twine, prek) passed
docs HTML build passed

Skips are pre-existing and platform-only: redis on macOS, SIGBREAK on Windows, and two PyPy-specific skips.

@jf-paquin-web
jf-paquin-web force-pushed the fix/xdist-worker-double-coverage branch from 24d6b81 to 7aa1540 Compare October 29, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant