Skip to content

Commit dbdc991

Browse files
authored
Fix test_embed.test_pre_initialization_sys_options() env vars (GH-14172)
test_pre_initialization_sys_options() of test_embed now removes PYTHON* environment variables like PYTHONWARNINGS.
1 parent ac7b1a3 commit dbdc991

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Lib/test/test_embed.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
API_ISOLATED = 3
2727

2828

29+
def remove_python_envvars():
30+
env = dict(os.environ)
31+
# Remove PYTHON* environment variables to get deterministic environment
32+
for key in list(env):
33+
if key.startswith('PYTHON'):
34+
del env[key]
35+
return env
36+
37+
2938
class EmbeddingTestsMixin:
3039
def setUp(self):
3140
here = os.path.abspath(__file__)
@@ -232,7 +241,8 @@ def test_pre_initialization_sys_options(self):
232241
Checks that sys.warnoptions and sys._xoptions can be set before the
233242
runtime is initialized (otherwise they won't be effective).
234243
"""
235-
env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path))
244+
env = remove_python_envvars()
245+
env['PYTHONPATH'] = os.pathsep.join(sys.path)
236246
out, err = self.run_embedded_interpreter(
237247
"test_pre_initialization_sys_options", env=env)
238248
expected_output = (
@@ -591,11 +601,7 @@ def check_global_config(self, configs):
591601
def check_all_configs(self, testname, expected_config=None,
592602
expected_preconfig=None, add_path=None, stderr=None,
593603
*, api):
594-
env = dict(os.environ)
595-
# Remove PYTHON* environment variables to get deterministic environment
596-
for key in list(env):
597-
if key.startswith('PYTHON'):
598-
del env[key]
604+
env = remove_python_envvars()
599605

600606
if api == API_ISOLATED:
601607
default_preconfig = self.PRE_CONFIG_ISOLATED

0 commit comments

Comments
 (0)