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 | |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 9 | import os |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 10 | import sys |
Victor Stinner | 3aac0ad | 2016-03-24 17:53:20 +0100 | [diff] [blame] | 11 | from test.libregrtest import main |
Chris Jerdonek | 517e925 | 2013-02-27 09:02:53 -0800 | [diff] [blame] | 12 | |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 13 | |
Victor Stinner | 3aac0ad | 2016-03-24 17:53:20 +0100 | [diff] [blame] | 14 | # Alias for backward compatibility (just in case) |
| 15 | main_in_temp_cwd = main |
Victor Stinner | 4ffcc3e | 2016-03-24 17:43:53 +0100 | [diff] [blame] | 16 | |
| 17 | |
| 18 | def _main(): |
| 19 | global __file__ |
| 20 | |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 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]))) |
Victor Stinner | 4ffcc3e | 2016-03-24 17:43:53 +0100 | [diff] [blame] | 27 | i = len(sys.path) - 1 |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 28 | while i >= 0: |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 29 | if os.path.abspath(os.path.normpath(sys.path[i])) == mydir: |
| 30 | del sys.path[i] |
Victor Stinner | 4ffcc3e | 2016-03-24 17:43:53 +0100 | [diff] [blame] | 31 | else: |
| 32 | i -= 1 |
Nick Coghlan | 4c4c0f2 | 2010-12-03 07:44:33 +0000 | [diff] [blame] | 33 | |
Florent Xicluna | dc69e72 | 2010-09-13 16:35:02 +0000 | [diff] [blame] | 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 |
Florent Xicluna | da7bfd5 | 2010-03-06 11:43:55 +0000 | [diff] [blame] | 41 | assert __file__ == os.path.abspath(sys.argv[0]) |
Ezio Melotti | 184bdfb | 2010-02-18 09:37:05 +0000 | [diff] [blame] | 42 | |
Victor Stinner | 4ffcc3e | 2016-03-24 17:43:53 +0100 | [diff] [blame] | 43 | main() |
| 44 | |
| 45 | |
| 46 | if __name__ == '__main__': |
| 47 | _main() |