Skip to content

Commit 0402b43

Browse files
committed
Cleanup regrtest.py
* Move code into a new _main() function * Fix loop to cleanup sys.path * Remove unused import
1 parent c5b8fc0 commit 0402b43

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Lib/test/regrtest.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,28 @@
1111

1212
import os
1313
import sys
14-
from test.libregrtest import main, main_in_temp_cwd
14+
from test.libregrtest import main_in_temp_cwd
1515

1616

17-
if __name__ == '__main__':
17+
# alias needed by other scripts
18+
main = main_in_temp_cwd
19+
20+
21+
def _main():
22+
global __file__
23+
1824
# Remove regrtest.py's own directory from the module search path. Despite
1925
# the elimination of implicit relative imports, this is still needed to
2026
# ensure that submodules of the test package do not inappropriately appear
2127
# as top-level modules even when people (or buildbots!) invoke regrtest.py
2228
# directly instead of using the -m switch
2329
mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
24-
i = len(sys.path)
30+
i = len(sys.path) - 1
2531
while i >= 0:
26-
i -= 1
2732
if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
2833
del sys.path[i]
34+
else:
35+
i -= 1
2936

3037
# findtestdir() gets the dirname out of __file__, so we have to make it
3138
# absolute before changing the working directory.
@@ -36,4 +43,8 @@
3643
# sanity check
3744
assert __file__ == os.path.abspath(sys.argv[0])
3845

39-
main_in_temp_cwd()
46+
main()
47+
48+
49+
if __name__ == '__main__':
50+
_main()

0 commit comments

Comments
 (0)