Skip to content

Commit 8da4a00

Browse files
committed
test: force local .pyc files in a stronger way.
On one machine, the built-in value of sys.pycache_prefix was '/Users/nbatchelder/Library/Caches/com.apple.python'
1 parent 802d09e commit 8da4a00

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tests/conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,17 @@ def reset_environment() -> Iterator[None]:
8282

8383

8484
@pytest.fixture(autouse=True)
85-
def reset_filesdotpy_globals() -> Iterator[None]:
85+
def reset_filesdotpy_globals() -> None:
8686
"""coverage/files.py has some unfortunate globals. Reset them every test."""
8787
set_relative_directory()
88-
yield
88+
89+
@pytest.fixture(autouse=True)
90+
def force_local_pyc_files() -> None:
91+
"""Ensure that .pyc files are written next to source files."""
92+
# For some tests, we need .pyc files written in the current directory,
93+
# so override any local setting.
94+
sys.pycache_prefix = None
95+
8996

9097
WORKER = os.getenv("PYTEST_XDIST_WORKER", "none")
9198

tox.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ install_command = python -m pip install -U {opts} {packages}
2727
passenv = *
2828
setenv =
2929
pypy3{,9,10,11}: COVERAGE_TEST_CORES=pytrace
30-
# For some tests, we need .pyc files written in the current directory,
31-
# so override any local setting.
32-
PYTHONPYCACHEPREFIX=
3330
# If we ever need a stronger way to suppress warnings:
3431
#PYTHONWARNINGS=ignore:removed in Python 3.14; use ast.Constant:DeprecationWarning
3532
# Disable CPython's color output

0 commit comments

Comments
 (0)