Skip to content
Merged
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
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import contextlib
import os
import site
import sys
import sysconfig
from pathlib import Path
Expand Down Expand Up @@ -30,6 +32,26 @@
HERE = Path(__file__).absolute().parent


def _strip_broken_namespace_pth_files() -> None:
# Legacy setuptools-generated *-nspkg.pth files (from PasteDeploy and repoze.lru, pulled in
# transitively by devpi-server) read sys._getframe(1).f_locals['sitedir']. Python 3.13
# rewrote site.py as a frozen module and this lookup no longer resolves, so each Python
# startup emits a KeyError to stderr that breaks tests asserting on subprocess stderr.
# Removing the files is safe: the paste and repoze namespaces still resolve via PEP 420.
legacy = b"sys._getframe(1).f_locals['sitedir']"
for raw in site.getsitepackages():
site_dir = Path(raw)
if not site_dir.is_dir():
continue
for pth in site_dir.glob("*-nspkg.pth"):
with contextlib.suppress(OSError):
if legacy in pth.read_bytes():
pth.unlink()


_strip_broken_namespace_pth_files()


@pytest.fixture(scope="session")
def value_error() -> Callable[[str], str]:
def _fmt(msg: str) -> str:
Expand Down
Loading