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