You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
committed
Activate xdist worker instrumentation before conftest.py loads
Worker-side setup previously ran inside pytest_configure(), which fires
after pytest has already auto-loaded every pytest11 entry-point plugin
and read the initial conftest.py files (verified against pytest's own
source: load_setuptools_entrypoints() precedes pytest_load_initial_conftests(),
both of which precede pytest_configure()). Anything a plugin or root
conftest.py imported in that window bypassed ImportManager entirely,
silently losing coverage in that worker -- the real mechanism behind
issue #84's "pre-imported modules" report (not, as filed, sys.modules
inheritance via fork -- xdist's local workers are separate subprocess.Popen
processes, not forks).
Moves the worker-activation logic to run as module-level code in
pytest_plugin.py instead, since it only ever needed environment variables
(already set before the worker process starts), never pytest's config
object. Since this module is itself what pytest imports via the same
entry-point autoload mechanism, top-level code here runs before
conftest.py is ever read, closing the gap for the dominant real-world
case with no retroactive repair needed.
Adds regression tests exercising a module pre-imported by conftest.py,
adapted from PR #85 (author @nurikk), who first diagnosed this gap and
prototyped a fix via post-hoc retroactive instrumentation of already-live
objects. Unfortunately that approach had significant issues of its own:
on Python <3.12 the rewritten bytecode was computed but never actually
reinstalled, and on 3.12+ branch coverage came back as a false 100% since
AST-level branch preinstrumentation never runs for already-imported
modules. A new branch-coverage regression test (not present in PR #85)
guards against that specific failure mode going forward.
Co-Authored-By: nurikk <1525421+nurikk@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
0 commit comments