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, |
Victor Stinner | 3e56c23 | 2016-09-21 17:12:50 +0200 | [diff] [blame^] | 29 | '-u', # Unbuffered stdout and stderr |
Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 30 | '-W', 'default', # Warnings set to 'default' |
| 31 | '-bb', # Warnings about bytes/bytearray |
| 32 | '-E', # Ignore environment variables |
| 33 | ] |
| 34 | # Allow user-specified interpreter options to override our defaults. |
| 35 | args.extend(test.support.args_from_interpreter_flags()) |
Serhiy Storchaka | 20f8728 | 2014-02-24 13:57:00 +0200 | [diff] [blame] | 36 | |
Serhiy Storchaka | 20f8728 | 2014-02-24 13:57:00 +0200 | [diff] [blame] | 37 | # Workaround for issue #20361 |
| 38 | args.extend(['-W', 'error::BytesWarning']) |
| 39 | |
Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 40 | args.extend(['-m', 'test', # Run the test suite |
| 41 | '-r', # Randomize test order |
| 42 | '-w', # Re-run failed tests in verbose mode |
| 43 | ]) |
Antoine Pitrou | 7f0a6dd | 2011-08-16 20:02:26 +0200 | [diff] [blame] | 44 | if sys.platform == 'win32': |
| 45 | args.append('-n') # Silence alerts under Windows |
Antoine Pitrou | ebdcd85 | 2012-05-18 18:33:07 +0200 | [diff] [blame] | 46 | 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] | 47 | args.extend(['-j', '0']) # Use all CPU cores |
| 48 | 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] | 49 | args.extend(['-u', 'all,-largefile,-audio,-gui']) |
Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 50 | args.extend(regrtest_args) |
| 51 | print(' '.join(args)) |
Zachary Ware | e12fa65 | 2014-07-07 13:39:59 -0500 | [diff] [blame] | 52 | if sys.platform == 'win32': |
| 53 | from subprocess import call |
Zachary Ware | 69d2d01 | 2014-07-07 15:07:46 -0500 | [diff] [blame] | 54 | sys.exit(call(args)) |
Zachary Ware | e12fa65 | 2014-07-07 13:39:59 -0500 | [diff] [blame] | 55 | else: |
| 56 | os.execv(sys.executable, args) |
Nadeem Vawda | 3c01d16 | 2011-08-01 23:48:26 +0200 | [diff] [blame] | 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | main(sys.argv[1:]) |