Skip to content

Commit 2e61506

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 23e1562 commit 2e61506

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
@@ -1158,10 +1158,16 @@ def test_import(self):
11581158
# Change of the module content
11591159
script = self.make_script("print(0)", name="module")
11601160

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

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

0 commit comments

Comments
 (0)