diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-24 16:43:53 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-24 16:43:53 (GMT) |
commit | 4ffcc3ee1e982b1c739a3c1d6fb948960b31c3dd (patch) | |
tree | c26f23497375d18420543e10933a6c1937705a69 /Lib/test/regrtest.py | |
parent | e40390473dc1303c550664457f5b7b2582592086 (diff) | |
download | cpython-4ffcc3ee1e982b1c739a3c1d6fb948960b31c3dd.zip cpython-4ffcc3ee1e982b1c739a3c1d6fb948960b31c3dd.tar.gz cpython-4ffcc3ee1e982b1c739a3c1d6fb948960b31c3dd.tar.bz2 |
Cleanup regrtest.py
* Move code into a new _main() function
* Fix loop to cleanup sys.path
* Remove unused import
Diffstat (limited to 'Lib/test/regrtest.py')
-rw-r--r-- | Lib/test/regrtest.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index fcc3937..9cbb926 100644 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -11,21 +11,28 @@ import importlib import os import sys -from test.libregrtest import main, main_in_temp_cwd +from test.libregrtest import main_in_temp_cwd -if __name__ == '__main__': +# alias needed by other scripts +main = main_in_temp_cwd + + +def _main(): + global __file__ + # Remove regrtest.py's own directory from the module search path. Despite # the elimination of implicit relative imports, this is still needed to # ensure that submodules of the test package do not inappropriately appear # as top-level modules even when people (or buildbots!) invoke regrtest.py # directly instead of using the -m switch mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0]))) - i = len(sys.path) + i = len(sys.path) - 1 while i >= 0: - i -= 1 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir: del sys.path[i] + else: + i -= 1 # findtestdir() gets the dirname out of __file__, so we have to make it # absolute before changing the working directory. @@ -36,4 +43,8 @@ if __name__ == '__main__': # sanity check assert __file__ == os.path.abspath(sys.argv[0]) - main_in_temp_cwd() + main() + + +if __name__ == '__main__': + _main() |