Skip to content

gh-162846: Fix test_compileall with PYTHONDONTWRITEBYTECODE or PYTHONOPTIMIZE set - #162847

Merged
StanFromIreland merged 2 commits into
python:mainfrom
Daranton:compileall-dontwritebytecode
Nov 30, 2026
Merged

StanFromIreland merged 2 commits into
python:mainfrom
Daranton:compileall-dontwritebytecode

Conversation

@Daranton

@Daranton Daranton commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

HardlinkDedupTestsBase.test_import starts a child interpreter with
__isolated=False, so the child inherits PYTHONDONTWRITEBYTECODE,
never rewrites the opt-1 pyc file, and the hardlink check fails.
PYTHONOPTIMIZE=2 breaks it too: the child then rewrites the opt-2
file instead. This unsets both variables around the child, following
the approach of gh-151626 for PYTHONPYCACHEPREFIX.

Tested with ./python -m test test_compileall, with and without
PYTHONDONTWRITEBYTECODE=1, PYTHONOPTIMIZE=1 and PYTHONOPTIMIZE=2.

@python-cla-bot

python-cla-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

HardlinkDedupTestsBase.test_import expects a child interpreter to
rewrite the opt-1 pyc file. The child inherits the environment, so
with PYTHONDONTWRITEBYTECODE set it never writes the file, and with
PYTHONOPTIMIZE=2 it writes the opt-2 file instead. Unset both
variables for the child.
@Daranton
Daranton force-pushed the compileall-dontwritebytecode branch from a192255 to bd6a0cc Compare November 30, 2026 01:09
@Daranton Daranton changed the title gh-162846: Fix test_compileall when PYTHONDONTWRITEBYTECODE is set gh-162846: Fix test_compileall with PYTHONDONTWRITEBYTECODE or PYTHONOPTIMIZE set Nov 30, 2026
@bedevere-app

bedevere-app Bot commented Nov 30, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@StanFromIreland StanFromIreland changed the title gh-162846: Fix test_compileall with PYTHONDONTWRITEBYTECODE or PYTHONOPTIMIZE set gh-162846: Fix test_compileall with PYTHONDONTWRITEBYTECODE or PYTHONOPTIMIZE set Nov 30, 2026
@StanFromIreland StanFromIreland added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes skip news and removed awaiting merge labels Nov 30, 2026
@StanFromIreland
StanFromIreland merged commit a394712 into python:main Nov 30, 2026
65 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @Daranton for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 30, 2026

Copy link
Copy Markdown

GH-162890 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 30, 2026
@bedevere-app

bedevere-app Bot commented Nov 30, 2026

Copy link
Copy Markdown

GH-162891 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 30, 2026
@Daranton
Daranton deleted the compileall-dontwritebytecode branch November 30, 2026 21:15
StanFromIreland added a commit that referenced this pull request Nov 30, 2026
…` or `PYTHONOPTIMIZE` set (GH-162847) (#162891)

(cherry picked from commit a394712)

Co-authored-by: Anton Darahan <darantonreal@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants