mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									ac7b1a3f32
								
							
						
					
					
						commit
						dbdc991a62
					
				
					 1 changed files with 12 additions and 6 deletions
				
			
		| 
						 | 
					@ -26,6 +26,15 @@
 | 
				
			||||||
API_ISOLATED = 3
 | 
					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:
 | 
					class EmbeddingTestsMixin:
 | 
				
			||||||
    def setUp(self):
 | 
					    def setUp(self):
 | 
				
			||||||
        here = os.path.abspath(__file__)
 | 
					        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
 | 
					        Checks that sys.warnoptions and sys._xoptions can be set before the
 | 
				
			||||||
        runtime is initialized (otherwise they won't be effective).
 | 
					        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(
 | 
					        out, err = self.run_embedded_interpreter(
 | 
				
			||||||
                        "test_pre_initialization_sys_options", env=env)
 | 
					                        "test_pre_initialization_sys_options", env=env)
 | 
				
			||||||
        expected_output = (
 | 
					        expected_output = (
 | 
				
			||||||
| 
						 | 
					@ -591,11 +601,7 @@ def check_global_config(self, configs):
 | 
				
			||||||
    def check_all_configs(self, testname, expected_config=None,
 | 
					    def check_all_configs(self, testname, expected_config=None,
 | 
				
			||||||
                     expected_preconfig=None, add_path=None, stderr=None,
 | 
					                     expected_preconfig=None, add_path=None, stderr=None,
 | 
				
			||||||
                     *, api):
 | 
					                     *, api):
 | 
				
			||||||
        env = dict(os.environ)
 | 
					        env = remove_python_envvars()
 | 
				
			||||||
        # Remove PYTHON* environment variables to get deterministic environment
 | 
					 | 
				
			||||||
        for key in list(env):
 | 
					 | 
				
			||||||
            if key.startswith('PYTHON'):
 | 
					 | 
				
			||||||
                del env[key]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if api == API_ISOLATED:
 | 
					        if api == API_ISOLATED:
 | 
				
			||||||
            default_preconfig = self.PRE_CONFIG_ISOLATED
 | 
					            default_preconfig = self.PRE_CONFIG_ISOLATED
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue