1#! /usr/bin/env python3 2 3""" 4Script to run Python regression tests. 5 6Run this script with -h or --help for documentation. 7""" 8 9# We import importlib *ASAP* in order to test #15386 10import importlib 11 12import os 13import sys 14from test.libregrtest import main 15 16 17# Alias for backward compatibility (just in case) 18main_in_temp_cwd = main 19 20 21def _main(): 22 global __file__ 23 24 # Remove regrtest.py's own directory from the module search path. Despite 25 # the elimination of implicit relative imports, this is still needed to 26 # ensure that submodules of the test package do not inappropriately appear 27 # as top-level modules even when people (or buildbots!) invoke regrtest.py 28 # directly instead of using the -m switch 29 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0]))) 30 i = len(sys.path) - 1 31 while i >= 0: 32 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir: 33 del sys.path[i] 34 else: 35 i -= 1 36 37 # findtestdir() gets the dirname out of __file__, so we have to make it 38 # absolute before changing the working directory. 39 # For example __file__ may be relative when running trace or profile. 40 # See issue #9323. 41 __file__ = os.path.abspath(__file__) 42 43 # sanity check 44 assert __file__ == os.path.abspath(sys.argv[0]) 45 46 main() 47 48 49if __name__ == '__main__': 50 _main() 51