[3.11] gh-84461: Use HOSTRUNNER to run regression tests (GH-93694) by miss-islington · Pull Request #93709 · python/cpython
import os import shlex import sys import sysconfig import test.support
def is_python_flag(arg): return arg.startswith('-p') or arg.startswith('--python')
def main(regrtest_args): args = [sys.executable, '-u', # Unbuffered stdout and stderr '-W', 'default', # Warnings set to 'default' '-bb', # Warnings about bytes/bytearray '-E', # Ignore environment variables ]
cross_compile = '_PYTHON_HOST_PLATFORM' in os.environ if (hostrunner := os.environ.get("_PYTHON_HOSTRUNNER")) is None: hostrunner = sysconfig.get_config_var("HOSTRUNNER") if cross_compile: # emulate -E, but keep PYTHONPATH + cross compile env vars, so # test executable can load correct sysconfigdata file. keep = { '_PYTHON_PROJECT_BASE', '_PYTHON_HOST_PLATFORM', '_PYTHON_SYSCONFIGDATA_NAME', 'PYTHONPATH' } environ = { name: value for name, value in os.environ.items() if not name.startswith(('PYTHON', '_PYTHON')) or name in keep } else: environ = os.environ.copy() args.append("-E")
# Allow user-specified interpreter options to override our defaults. args.extend(test.support.args_from_interpreter_flags())
if cross_compile and hostrunner: # If HOSTRUNNER is set and -p/--python option is not given, then # use hostrunner to execute python binary for tests. if not any(is_python_flag(arg) for arg in regrtest_args): buildpython = sysconfig.get_config_var("BUILDPYTHON") args.extend(["--python", f"{hostrunner} {buildpython}"])
args.extend(regrtest_args) print(' '.join(args))
print(shlex.join(args)) if sys.platform == 'win32': from subprocess import call sys.exit(call(args)) else: os.execv(sys.executable, args) os.execve(sys.executable, args, environ)
if __name__ == '__main__':