Skip to content

🧪 test(conftest): strip broken nspkg.pth files under py3.15#3937

Open
gaborbernat wants to merge 1 commit into
tox-dev:mainfrom
gaborbernat:3.15
Open

🧪 test(conftest): strip broken nspkg.pth files under py3.15#3937
gaborbernat wants to merge 1 commit into
tox-dev:mainfrom
gaborbernat:3.15

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat commented May 11, 2026

Six tests in the local subprocess and parallel suites fail on the weekly Python 3.15 check (run 25667044284) because every spawned interpreter prints a KeyError to stderr before user code runs, and the assertions compare stderr byte-for-byte.

The noise originates in the legacy *-nspkg.pth files shipped by PasteDeploy 3.1.0 and repoze.lru 0.7, both pulled in transitively by devpi-serverpyramid. Those pth files call sys._getframe(1).f_locals['sitedir'], which worked when site.py walked its own frame. PEP 829 (CPython #149109) replaced that machinery with a deferred _exec_imports() that has no sitedir local, so every interpreter startup raises KeyError: "local variable ''sitedir'' is not defined". The regression is tracked upstream in CPython #149671.

This is genuinely an upstream problem: the proper fix lives either in CPython (restoring compatibility with legacy .pth hacks, or providing a migration path) or in setuptools (which still generates these pth files for namespace_packages= declarations even though pkg_resources was removed in 82.0.0). The paste and repoze namespaces would still resolve via PEP 420 without the .pth shim, so the affected packages could also drop namespace_packages= upstream.

Until any of those land, this patch removes the offending pth files at conftest import — gated by the broken f_locals['sitedir'] substring so unrelated namespace pth files are untouched, and wrapped in contextlib.suppress(OSError) to stay idempotent under xdist workers racing on the same file. Revert once the upstream fix is available.

PasteDeploy and repoze.lru, pulled in transitively by devpi-server,
install legacy setuptools nspkg.pth files that read
sys._getframe(1).f_locals['sitedir']. Python 3.13 rewrote site.py as a
frozen module and that local no longer exists, so every interpreter
spawn emits a KeyError to stderr. Six tests across local_subprocess and
parallel suites assert on exact subprocess stderr and fail under 3.15.

Removing the offending pth files at conftest import is the smallest
surgical fix: the paste and repoze namespaces still resolve via PEP 420
implicit packages, so devpi-server keeps working, and the cleanup is
idempotent under xdist.
@gaborbernat gaborbernat added bug:upstream something does not behave as it should, but can't or shouldn't be fixed in tox, but in a dependency type:internal should have no impact on the user (refactoring, infrastructure, tools, etc.) labels May 11, 2026
@gaborbernat gaborbernat requested a review from rahuldevikar as a code owner May 11, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:skip bug:upstream something does not behave as it should, but can't or shouldn't be fixed in tox, but in a dependency type:internal should have no impact on the user (refactoring, infrastructure, tools, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant