Skip to content

Commit 62c95b1

Browse files
DarantonStanFromIreland
authored andcommitted
gh-162846: Fix test_compileall with PYTHONDONTWRITEBYTECODE or PYTHONOPTIMIZE set (GH-162847)
(cherry picked from commit a3947124f3dad907152395aa238ee4b99d7539b8) Co-authored-by: Anton Darahan <darantonreal@gmail.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 932c91f commit 62c95b1

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎Lib/test/test_compileall.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,10 +1154,16 @@ def test_import(self):
11541154
# Change of the module content
11551155
script = self.make_script("print(0)", name="module")
11561156

1157-
# Import the module in Python with -O (optimization level 1)
1158-
script_helper.assert_python_ok(
1159-
"-O", "-c", "import module", __isolated=False, PYTHONPATH=self.path
1160-
)
1157+
# Import the module in Python with -O (optimization level 1).
1158+
# The child must write the opt-1 pyc file, so ignore any ambient
1159+
# PYTHONDONTWRITEBYTECODE or PYTHONOPTIMIZE.
1160+
with os_helper.EnvironmentVarGuard() as env:
1161+
env.unset('PYTHONDONTWRITEBYTECODE')
1162+
env.unset('PYTHONOPTIMIZE')
1163+
script_helper.assert_python_ok(
1164+
"-O", "-c", "import module",
1165+
__isolated=False, PYTHONPATH=self.path
1166+
)
11611167

11621168
# Only opt-1.pyc is changed
11631169
self.assertEqual(inode, os.stat(pycs[0]).st_ino)

0 commit comments

Comments
 (0)