Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 1 | """Run Python's test suite in a fast, rigorous way. |
| 2 | |
Nadeem Vawda | 328b501 | 2011-08-02 10:16:45 +0200 | [diff] [blame] | 3 | The defaults are meant to be reasonably thorough, while skipping certain |
| 4 | tests that can be time-consuming or resource-intensive (e.g. largefile), |
| 5 | or distracting (e.g. audio and gui). These defaults can be overridden by |
| 6 | simply passing a -u option to this script. |
Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 7 | |
| 8 | """ |
| 9 | |
| 10 | import os |
| 11 | import sys |
| 12 | import test.support |
Antoine Pitrou | ebdcd85 | 2012-05-18 18:33:07 +0200 | [diff] [blame] | 13 | try: |
| 14 | import threading |
| 15 | except ImportError: |
| 16 | threading = None |
Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 17 | |
| 18 | |
| 19 | def is_multiprocess_flag(arg): |
| 20 | return arg.startswith('-j') or arg.startswith('--multiprocess') |
| 21 | |
| 22 | |
| 23 | def is_resource_use_flag(arg): |
| 24 | return arg.startswith('-u') or arg.startswith('--use') |
| 25 | |
| 26 | |
| 27 | def 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()) |
Serhiy Storchaka | 20f8728 | 2014-02-24 13:57:00 +0200 | [diff] [blame] | 35 | |
| 36 | # Workaround for issue #20355 |
| 37 | os.environ.pop("PYTHONWARNINGS", None) |
| 38 | # Workaround for issue #20361 |
| 39 | args.extend(['-W', 'error::BytesWarning']) |
| 40 | |
Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 41 | args.extend(['-m', 'test', # Run the test suite |
| 42 | '-r', # Randomize test order |
| 43 | '-w', # Re-run failed tests in verbose mode |
| 44 | ]) |
Antoine Pitrou | 7f0a6dd | 2011-08-16 20:02:26 +0200 | [diff] [blame] | 45 | if sys.platform == 'win32': |
| 46 | args.append('-n') # Silence alerts under Windows |
Antoine Pitrou | ebdcd85 | 2012-05-18 18:33:07 +0200 | [diff] [blame] | 47 | if threading and not any(is_multiprocess_flag(arg) for arg in regrtest_args): |
Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 48 | args.extend(['-j', '0']) # Use all CPU cores |
| 49 | if not any(is_resource_use_flag(arg) for arg in regrtest_args): |
Antoine Pitrou | 87ae0a2 | 2011-10-01 16:41:48 +0200 | [diff] [blame] | 50 | args.extend(['-u', 'all,-largefile,-audio,-gui']) |
Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 51 | args.extend(regrtest_args) |
| 52 | print(' '.join(args)) |
| 53 | os.execv(sys.executable, args) |
| 54 | |
| 55 | |
| 56 | if __name__ == '__main__': |
| 57 | main(sys.argv[1:]) |