2011-08-01 18:48:26 -03:00
|
|
|
"""Run Python's test suite in a fast, rigorous way.
|
|
|
|
|
2011-08-02 05:16:45 -03:00
|
|
|
The defaults are meant to be reasonably thorough, while skipping certain
|
|
|
|
tests that can be time-consuming or resource-intensive (e.g. largefile),
|
|
|
|
or distracting (e.g. audio and gui). These defaults can be overridden by
|
|
|
|
simply passing a -u option to this script.
|
2011-08-01 18:48:26 -03:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2022-06-11 03:42:23 -03:00
|
|
|
import shlex
|
2011-08-01 18:48:26 -03:00
|
|
|
import sys
|
2022-06-11 03:42:23 -03:00
|
|
|
import sysconfig
|
2011-08-01 18:48:26 -03:00
|
|
|
import test.support
|
|
|
|
|
|
|
|
|
|
|
|
def is_multiprocess_flag(arg):
|
|
|
|
return arg.startswith('-j') or arg.startswith('--multiprocess')
|
|
|
|
|
|
|
|
|
|
|
|
def is_resource_use_flag(arg):
|
|
|
|
return arg.startswith('-u') or arg.startswith('--use')
|
|
|
|
|
2022-06-11 03:42:23 -03:00
|
|
|
def is_python_flag(arg):
|
|
|
|
return arg.startswith('-p') or arg.startswith('--python')
|
|
|
|
|
2011-08-01 18:48:26 -03:00
|
|
|
|
|
|
|
def main(regrtest_args):
|
|
|
|
args = [sys.executable,
|
2016-09-21 12:12:50 -03:00
|
|
|
'-u', # Unbuffered stdout and stderr
|
2011-08-01 18:48:26 -03:00
|
|
|
'-W', 'default', # Warnings set to 'default'
|
|
|
|
'-bb', # Warnings about bytes/bytearray
|
|
|
|
]
|
2020-04-22 19:29:27 -03:00
|
|
|
|
2022-06-11 03:42:23 -03:00
|
|
|
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")
|
|
|
|
|
2011-08-01 18:48:26 -03:00
|
|
|
# Allow user-specified interpreter options to override our defaults.
|
|
|
|
args.extend(test.support.args_from_interpreter_flags())
|
2014-02-24 07:57:00 -04:00
|
|
|
|
2011-08-01 18:48:26 -03:00
|
|
|
args.extend(['-m', 'test', # Run the test suite
|
|
|
|
'-r', # Randomize test order
|
|
|
|
'-w', # Re-run failed tests in verbose mode
|
|
|
|
])
|
2011-08-16 15:02:26 -03:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
args.append('-n') # Silence alerts under Windows
|
2017-09-10 15:32:13 -03:00
|
|
|
if not any(is_multiprocess_flag(arg) for arg in regrtest_args):
|
2022-06-11 03:42:23 -03:00
|
|
|
if cross_compile and hostrunner:
|
2022-06-13 14:51:04 -03:00
|
|
|
# For now use only two cores for cross-compiled builds;
|
2022-06-11 03:42:23 -03:00
|
|
|
# hostrunner can be expensive.
|
2022-06-13 14:51:04 -03:00
|
|
|
args.extend(['-j', '2'])
|
2022-06-11 03:42:23 -03:00
|
|
|
else:
|
|
|
|
args.extend(['-j', '0']) # Use all CPU cores
|
2011-08-01 18:48:26 -03:00
|
|
|
if not any(is_resource_use_flag(arg) for arg in regrtest_args):
|
2011-10-01 11:41:48 -03:00
|
|
|
args.extend(['-u', 'all,-largefile,-audio,-gui'])
|
2022-06-11 03:42:23 -03:00
|
|
|
|
|
|
|
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}"])
|
|
|
|
|
2011-08-01 18:48:26 -03:00
|
|
|
args.extend(regrtest_args)
|
2022-06-11 03:42:23 -03:00
|
|
|
|
|
|
|
print(shlex.join(args))
|
2014-07-07 15:39:59 -03:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
from subprocess import call
|
2014-07-07 17:07:46 -03:00
|
|
|
sys.exit(call(args))
|
2014-07-07 15:39:59 -03:00
|
|
|
else:
|
2022-06-11 03:42:23 -03:00
|
|
|
os.execve(sys.executable, args, environ)
|
2011-08-01 18:48:26 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main(sys.argv[1:])
|