1"""Run Python's test suite in a fast, rigorous way.
2
3The defaults are meant to be reasonably thorough, while skipping certain
4tests that can be time-consuming or resource-intensive (e.g. largefile),
5or distracting (e.g. audio and gui). These defaults can be overridden by
6simply passing a -u option to this script.
7
8"""
9
10import os
11import sys
12import test.support
13try:
14    import threading
15except ImportError:
16    threading = None
17
18
19def is_multiprocess_flag(arg):
20    return arg.startswith('-j') or arg.startswith('--multiprocess')
21
22
23def is_resource_use_flag(arg):
24    return arg.startswith('-u') or arg.startswith('--use')
25
26
27def main(regrtest_args):
28    args = [sys.executable,
29            '-W', 'default',      # Warnings set to 'default'
30            '-bb',                # Warnings about bytes/bytearray
31            '-E',                 # Ignore environment variables
32            ]
33    # Allow user-specified interpreter options to override our defaults.
34    args.extend(test.support.args_from_interpreter_flags())
35
36    # Workaround for issue #20361
37    args.extend(['-W', 'error::BytesWarning'])
38
39    args.extend(['-m', 'test',    # Run the test suite
40                 '-r',            # Randomize test order
41                 '-w',            # Re-run failed tests in verbose mode
42                 ])
43    if sys.platform == 'win32':
44        args.append('-n')         # Silence alerts under Windows
45    if threading and not any(is_multiprocess_flag(arg) for arg in regrtest_args):
46        args.extend(['-j', '0'])  # Use all CPU cores
47    if not any(is_resource_use_flag(arg) for arg in regrtest_args):
48        args.extend(['-u', 'all,-largefile,-audio,-gui'])
49    args.extend(regrtest_args)
50    print(' '.join(args))
51    if sys.platform == 'win32':
52        from subprocess import call
53        sys.exit(call(args))
54    else:
55        os.execv(sys.executable, args)
56
57
58if __name__ == '__main__':
59    main(sys.argv[1:])
60