run_tests.py 1.8 KB

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