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
{{ message }}
Repository navigation
test_compileall: HardlinkDedupTests test_import fails with PYTHONDONTWRITEBYTECODE or PYTHONOPTIMIZE set #162846
HardlinkDedupTestsNoSourceEpoch.test_import and HardlinkDedupTestsWithSourceEpoch.test_import fail when the test suite is
run with PYTHONDONTWRITEBYTECODE set, which is common in container images:
$ PYTHONDONTWRITEBYTECODE=1 ./python -m test test_compileall
...
FAIL: test_import (test.test_compileall.HardlinkDedupTestsNoSourceEpoch.test_import)
----------------------------------------------------------------------
Traceback (most recent call last):
...
File "Lib/test/test_compileall.py", line 1169, in test_import
self.assertFalse(is_hardlink(pycs[1], pycs[2]))
AssertionError: True is not false
The test changes the source and then imports it in a child process with -O,
expecting the child to rewrite the opt-1 pyc file and so break its hardlink to
the opt-2 file. The child is started with __isolated=False (it needs PYTHONPATH), so it inherits PYTHONDONTWRITEBYTECODE, never writes the pyc,
and the hardlink stays.
PYTHONOPTIMIZE=2 breaks the test the same way: the child then runs at
optimization level 2 and rewrites the opt-2 file instead of the opt-1 file.
The test was added in gh-84675 (bpo-40495), after the suite was made to pass
with -B/PYTHONDONTWRITEBYTECODE in gh-55629 (bpo-11420). gh-151626 fixed
the same kind of problem for PYTHONPYCACHEPREFIX.
changed the title [-]test_compileall: HardlinkDedupTests test_import fails when PYTHONDONTWRITEBYTECODE is set[/-][+]test_compileall: HardlinkDedupTests test_import fails with PYTHONDONTWRITEBYTECODE or PYTHONOPTIMIZE set[/+]on Nov 30, 2026
Activity
pythongh-162846: Fix test_compileall when PYTHONDONTWRITEBYTECODE is set
pythongh-162846: Fix test_compileall when PYTHONDONTWRITEBYTECODE is set
[-]test_compileall: HardlinkDedupTests test_import fails when PYTHONDONTWRITEBYTECODE is set[/-][+]test_compileall: HardlinkDedupTests test_import fails with PYTHONDONTWRITEBYTECODE or PYTHONOPTIMIZE set[/+]gh-162846: Fix `test_compileall` with `PYTHONDONTWRITEBYTECODE` or `P…
[3.14] gh-162846: Fix `test_compileall` with `PYTHONDONTWRITEBYTECODE…