[Python-checkins] Fix test_embed.test_pre_initialization_sys_options() env vars (GH-14172)

Miss Islington (bot) webhook-mailer at python.org
Mon Jun 17 18:31:47 EDT 2019


https://github.com/python/cpython/commit/69610f86d3754839e7f476c46995a92e1cbc7ed2
commit: 69610f86d3754839e7f476c46995a92e1cbc7ed2
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-06-17T15:31:43-07:00
summary:

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.
(cherry picked from commit dbdc991a62bc2b3393d287e90292e3603f47d98a)

Co-authored-by: Victor Stinner <vstinner at redhat.com>

files:
M Lib/test/test_embed.py

diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index a39ef2babbdb..1bc8d3aaee02 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -26,6 +26,15 @@
 API_ISOLATED = 3
 
 
+def remove_python_envvars():
+    env = dict(os.environ)
+    # Remove PYTHON* environment variables to get deterministic environment
+    for key in list(env):
+        if key.startswith('PYTHON'):
+            del env[key]
+    return env
+
+
 class EmbeddingTestsMixin:
     def setUp(self):
         here = os.path.abspath(__file__)
@@ -232,7 +241,8 @@ def test_pre_initialization_sys_options(self):
         Checks that sys.warnoptions and sys._xoptions can be set before the
         runtime is initialized (otherwise they won't be effective).
         """
-        env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path))
+        env = remove_python_envvars()
+        env['PYTHONPATH'] = os.pathsep.join(sys.path)
         out, err = self.run_embedded_interpreter(
                         "test_pre_initialization_sys_options", env=env)
         expected_output = (
@@ -591,11 +601,7 @@ def check_global_config(self, configs):
     def check_all_configs(self, testname, expected_config=None,
                      expected_preconfig=None, add_path=None, stderr=None,
                      *, api):
-        env = dict(os.environ)
-        # Remove PYTHON* environment variables to get deterministic environment
-        for key in list(env):
-            if key.startswith('PYTHON'):
-                del env[key]
+        env = remove_python_envvars()
 
         if api == API_ISOLATED:
             default_preconfig = self.PRE_CONFIG_ISOLATED



More information about the Python-checkins mailing list