mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	Skip some tests that require a subinterpreter launched with -E or -I when the
interpreter under test is being run in an environment that requires the use of environment variables such as PYTHONHOME in order to function at all. Adds a test.script_helper.interpreter_requires_environment() function to be used with @unittest.skipIf on stdlib test methods requiring this.
This commit is contained in:
		
						commit
						8f2fae1e7d
					
				
					 4 changed files with 82 additions and 2 deletions
				
			
		|  | @ -15,6 +15,41 @@ | |||
| from importlib.util import source_from_cache | ||||
| from test.support import make_legacy_pyc, strip_python_stderr, temp_dir | ||||
| 
 | ||||
| 
 | ||||
| # Cached result of the expensive test performed in the function below. | ||||
| __cached_interp_requires_environment = None | ||||
| 
 | ||||
| def interpreter_requires_environment(): | ||||
|     """ | ||||
|     Returns True if our sys.executable interpreter requires environment | ||||
|     variables in order to be able to run at all. | ||||
| 
 | ||||
|     This is designed to be used with @unittest.skipIf() to annotate tests | ||||
|     that need to use an assert_python*() function to launch an isolated | ||||
|     mode (-I) or no environment mode (-E) sub-interpreter process. | ||||
| 
 | ||||
|     A normal build & test does not run into this situation but it can happen | ||||
|     when trying to run the standard library test suite from an interpreter that | ||||
|     doesn't have an obvious home with Python's current home finding logic. | ||||
| 
 | ||||
|     Setting PYTHONHOME is one way to get most of the testsuite to run in that | ||||
|     situation.  PYTHONPATH or PYTHONUSERSITE are other common envirnonment | ||||
|     variables that might impact whether or not the interpreter can start. | ||||
|     """ | ||||
|     global __cached_interp_requires_environment | ||||
|     if __cached_interp_requires_environment is None: | ||||
|         # Try running an interpreter with -E to see if it works or not. | ||||
|         try: | ||||
|             subprocess.check_call([sys.executable, '-E', | ||||
|                                    '-c', 'import sys; sys.exit(0)']) | ||||
|         except subprocess.CalledProcessError: | ||||
|             __cached_interp_requires_environment = True | ||||
|         else: | ||||
|             __cached_interp_requires_environment = False | ||||
| 
 | ||||
|     return __cached_interp_requires_environment | ||||
| 
 | ||||
| 
 | ||||
| # Executing the interpreter in a subprocess | ||||
| def _assert_python(expected_success, *args, **env_vars): | ||||
|     if '__isolated' in env_vars: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gregory P. Smith
						Gregory P. Smith