blob: 21b0edfd073d6e3c3e218d2ef7629c0359e2089a [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#! /usr/bin/env python3
Guido van Rossum152494a1996-12-20 03:12:20 +00002
R. David Murray0ba81e02010-04-26 17:02:32 +00003"""
Chris Jerdonekd6c18dc2012-12-27 18:53:12 -08004Script to run Python regression tests.
Guido van Rossum152494a1996-12-20 03:12:20 +00005
Chris Jerdonekd6c18dc2012-12-27 18:53:12 -08006Run this script with -h or --help for documentation.
7"""
8
Nick Coghlanbe7e49f2012-07-20 23:40:09 +10009# We import importlib *ASAP* in order to test #15386
10import importlib
11
Christian Heimesb186d002008-03-18 15:15:01 +000012import os
Christian Heimesb186d002008-03-18 15:15:01 +000013import sys
Victor Stinner3aac0ad2016-03-24 17:53:20 +010014from test.libregrtest import main
Chris Jerdonek517e9252013-02-27 09:02:53 -080015
Nick Coghlan4c4c0f22010-12-03 07:44:33 +000016
Victor Stinner3aac0ad2016-03-24 17:53:20 +010017# Alias for backward compatibility (just in case)
18main_in_temp_cwd = main
Victor Stinner4ffcc3e2016-03-24 17:43:53 +010019
20
21def _main():
22 global __file__
23
Nick Coghlan4c4c0f22010-12-03 07:44:33 +000024 # 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])))
Victor Stinner4ffcc3e2016-03-24 17:43:53 +010030 i = len(sys.path) - 1
Nick Coghlan4c4c0f22010-12-03 07:44:33 +000031 while i >= 0:
Nick Coghlan4c4c0f22010-12-03 07:44:33 +000032 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
33 del sys.path[i]
Victor Stinner4ffcc3e2016-03-24 17:43:53 +010034 else:
35 i -= 1
Nick Coghlan4c4c0f22010-12-03 07:44:33 +000036
Florent Xiclunadc69e722010-09-13 16:35:02 +000037 # 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
Florent Xiclunada7bfd52010-03-06 11:43:55 +000044 assert __file__ == os.path.abspath(sys.argv[0])
Ezio Melotti184bdfb2010-02-18 09:37:05 +000045
Victor Stinner4ffcc3e2016-03-24 17:43:53 +010046 main()
47
48
49if __name__ == '__main__':
50 _main()