Benjamin Peterson | 90f5ba5 | 2010-03-11 22:53:45 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 2 | |
R. David Murray | 0ba81e0 | 2010-04-26 17:02:32 +0000 | [diff] [blame] | 3 | """ |
Chris Jerdonek | d6c18dc | 2012-12-27 18:53:12 -0800 | [diff] [blame] | 4 | Script to run Python regression tests. |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 5 | |
Chris Jerdonek | d6c18dc | 2012-12-27 18:53:12 -0800 | [diff] [blame] | 6 | Run this script with -h or --help for documentation. |
| 7 | """ |
| 8 | |
Nick Coghlan | be7e49f | 2012-07-20 23:40:09 +1000 | [diff] [blame] | 9 | # We import importlib *ASAP* in order to test #15386 |
| 10 | import importlib |
| 11 | |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 12 | import os |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 13 | import sys |
Victor Stinner | 3aac0ad | 2016-03-24 17:53:20 +0100 | [diff] [blame] | 14 | from test.libregrtest import main |
Chris Jerdonek | 517e925 | 2013-02-27 09:02:53 -0800 | [diff] [blame] | 15 | |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 16 | |
Victor Stinner | 3aac0ad | 2016-03-24 17:53:20 +0100 | [diff] [blame] | 17 | # Alias for backward compatibility (just in case) |
| 18 | main_in_temp_cwd = main |
Victor Stinner | 4ffcc3e | 2016-03-24 17:43:53 +0100 | [diff] [blame] | 19 | |
| 20 | |
| 21 | def _main(): |
| 22 | global __file__ |
| 23 | |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 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]))) |
Victor Stinner | 4ffcc3e | 2016-03-24 17:43:53 +0100 | [diff] [blame] | 30 | i = len(sys.path) - 1 |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 31 | while i >= 0: |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 32 | if os.path.abspath(os.path.normpath(sys.path[i])) == mydir: |
| 33 | del sys.path[i] |
Victor Stinner | 4ffcc3e | 2016-03-24 17:43:53 +0100 | [diff] [blame] | 34 | else: |
| 35 | i -= 1 |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 36 | |
Florent Xicluna | dc69e72 | 2010-09-13 16:35:02 +0000 | [diff] [blame] | 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 |
Florent Xicluna | da7bfd5 | 2010-03-06 11:43:55 +0000 | [diff] [blame] | 44 | assert __file__ == os.path.abspath(sys.argv[0]) |
Ezio Melotti | 184bdfb | 2010-02-18 09:37:05 +0000 | [diff] [blame] | 45 | |
Victor Stinner | 4ffcc3e | 2016-03-24 17:43:53 +0100 | [diff] [blame] | 46 | main() |
| 47 | |
| 48 | |
| 49 | if __name__ == '__main__': |
| 50 | _main() |