|
26 | 26 | API_ISOLATED = 3
|
27 | 27 |
|
28 | 28 |
|
| 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 | + |
29 | 38 | class EmbeddingTestsMixin:
|
30 | 39 | def setUp(self):
|
31 | 40 | here = os.path.abspath(__file__)
|
@@ -232,7 +241,8 @@ def test_pre_initialization_sys_options(self):
|
232 | 241 | Checks that sys.warnoptions and sys._xoptions can be set before the
|
233 | 242 | runtime is initialized (otherwise they won't be effective).
|
234 | 243 | """
|
235 |
| - env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path)) |
| 244 | + env = remove_python_envvars() |
| 245 | + env['PYTHONPATH'] = os.pathsep.join(sys.path) |
236 | 246 | out, err = self.run_embedded_interpreter(
|
237 | 247 | "test_pre_initialization_sys_options", env=env)
|
238 | 248 | expected_output = (
|
@@ -591,11 +601,7 @@ def check_global_config(self, configs):
|
591 | 601 | def check_all_configs(self, testname, expected_config=None,
|
592 | 602 | expected_preconfig=None, add_path=None, stderr=None,
|
593 | 603 | *, 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() |
599 | 605 |
|
600 | 606 | if api == API_ISOLATED:
|
601 | 607 | default_preconfig = self.PRE_CONFIG_ISOLATED
|
|
0 commit comments