Skip to content

Commit 7ffa11f

Browse files
vstinnerGlyphack
authored andcommitted
pythongh-109566: Fix regrtest Python options for WASM/WASI (python#109954)
WASM and WASI buildbots use multiple PYTHON environment variables such as PYTHONPATH and _PYTHON_HOSTRUNNER. Don't use -E if the --python=COMMAND option is used.
1 parent 4bb49f3 commit 7ffa11f

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

Lib/test/libregrtest/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,12 @@ def _add_python_opts(self):
504504
if sys.flags.bytes_warning < 2:
505505
python_opts.append('-bb')
506506

507-
# Ignore PYTHON* environment variables
508-
if not sys.flags.ignore_environment:
509-
python_opts.append('-E')
507+
# WASM/WASI buildbot builders pass multiple PYTHON environment
508+
# variables such as PYTHONPATH and _PYTHON_HOSTRUNNER.
509+
if not self.python_cmd:
510+
# Ignore PYTHON* environment variables
511+
if not sys.flags.ignore_environment:
512+
python_opts.append('-E')
510513

511514
if not python_opts:
512515
return

Lib/test/libregrtest/worker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ def create_worker_process(runtests: RunTests, output_fd: int,
2222
python_cmd = runtests.python_cmd
2323
worker_json = runtests.as_json()
2424

25+
python_opts = support.args_from_interpreter_flags()
2526
if python_cmd is not None:
2627
executable = python_cmd
28+
# Remove -E option, since --python=COMMAND can set PYTHON environment
29+
# variables, such as PYTHONPATH, in the worker process.
30+
python_opts = [opt for opt in python_opts if opt != "-E"]
2731
else:
2832
executable = (sys.executable,)
29-
cmd = [*executable, *support.args_from_interpreter_flags(),
33+
cmd = [*executable, *python_opts,
3034
'-u', # Unbuffered stdout and stderr
3135
'-m', 'test.libregrtest.worker',
3236
worker_json]

Lib/test/test_regrtest.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,16 +1965,20 @@ def test_dev_mode(self):
19651965
self.check_executed_tests(output, tests,
19661966
stats=len(tests), parallel=True)
19671967

1968-
def check_reexec(self, option):
1968+
def check_add_python_opts(self, option):
19691969
# --fast-ci and --slow-ci add "-u -W default -bb -E" options to Python
19701970
code = textwrap.dedent(r"""
19711971
import sys
19721972
import unittest
1973+
from test import support
19731974
try:
19741975
from _testinternalcapi import get_config
19751976
except ImportError:
19761977
get_config = None
19771978
1979+
# WASI/WASM buildbots don't use -E option
1980+
use_environment = (support.is_emscripten or support.is_wasi)
1981+
19781982
class WorkerTests(unittest.TestCase):
19791983
@unittest.skipUnless(get_config is None, 'need get_config()')
19801984
def test_config(self):
@@ -1986,7 +1990,7 @@ def test_config(self):
19861990
# -bb option
19871991
self.assertTrue(config['bytes_warning'], 2)
19881992
# -E option
1989-
self.assertTrue(config['use_environment'], 0)
1993+
self.assertTrue(config['use_environment'], use_environment)
19901994
19911995
def test_python_opts(self):
19921996
# -u option
@@ -2000,7 +2004,8 @@ def test_python_opts(self):
20002004
self.assertEqual(sys.flags.bytes_warning, 2)
20012005
20022006
# -E option
2003-
self.assertTrue(sys.flags.ignore_environment)
2007+
self.assertEqual(not sys.flags.ignore_environment,
2008+
use_environment)
20042009
""")
20052010
testname = self.create_test(code=code)
20062011

@@ -2018,7 +2023,7 @@ def test_python_opts(self):
20182023
def test_add_python_opts(self):
20192024
for opt in ("--fast-ci", "--slow-ci"):
20202025
with self.subTest(opt=opt):
2021-
self.check_reexec(opt)
2026+
self.check_add_python_opts(opt)
20222027

20232028

20242029
class TestUtils(unittest.TestCase):

0 commit comments

Comments
 (0)