[Python-checkins] cpython: Cleanup regrtest.py
victor.stinner
python-checkins at python.org
Thu Mar 24 12:54:16 EDT 2016
https://hg.python.org/cpython/rev/5b6c1d43e7dc
changeset: 100721:5b6c1d43e7dc
user: Victor Stinner <victor.stinner at gmail.com>
date: Thu Mar 24 17:43:53 2016 +0100
summary:
Cleanup regrtest.py
* Move code into a new _main() function
* Fix loop to cleanup sys.path
* Remove unused import
files:
Lib/test/regrtest.py | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -11,21 +11,28 @@
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 @@
# sanity check
assert __file__ == os.path.abspath(sys.argv[0])
- main_in_temp_cwd()
+ main()
+
+
+if __name__ == '__main__':
+ _main()
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list