Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 7c725d1

Browse files
author
Anselm Kruis
committed
Merge branch master into master-slp
2 parents 483d81b + 3aac0ad commit 7c725d1

File tree

8 files changed

+52
-39
lines changed

8 files changed

+52
-39
lines changed

Lib/test/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
from test import regrtest
2-
3-
regrtest.main_in_temp_cwd()
1+
from test.libregrtest import main
2+
main()

Lib/test/autotest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# This should be equivalent to running regrtest.py from the cmdline.
22
# It can be especially handy if you're in an interactive shell, e.g.,
33
# from test import autotest.
4-
5-
from test import regrtest
6-
regrtest.main()
4+
from test.libregrtest import main
5+
main()

Lib/test/libregrtest/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
# We import importlib *ASAP* in order to test #15386
2+
import importlib
3+
14
from test.libregrtest.cmdline import _parse_args, RESOURCE_NAMES
2-
from test.libregrtest.main import main, main_in_temp_cwd
5+
from test.libregrtest.main import main

Lib/test/libregrtest/main.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,28 @@ def finalize(self):
415415
os.system("leaks %d" % os.getpid())
416416

417417
def main(self, tests=None, **kwargs):
418+
global TEMPDIR
419+
420+
if sysconfig.is_python_build():
421+
try:
422+
os.mkdir(TEMPDIR)
423+
except FileExistsError:
424+
pass
425+
426+
# Define a writable temp dir that will be used as cwd while running
427+
# the tests. The name of the dir includes the pid to allow parallel
428+
# testing (see the -j option).
429+
test_cwd = 'test_python_{}'.format(os.getpid())
430+
test_cwd = os.path.join(TEMPDIR, test_cwd)
431+
432+
# Run the tests in a context manager that temporarily changes the CWD to a
433+
# temporary and writable directory. If it's not possible to create or
434+
# change the CWD, the original CWD will be used. The original CWD is
435+
# available from support.SAVEDCWD.
436+
with support.temp_cwd(test_cwd, quiet=True):
437+
self._main(tests, kwargs)
438+
439+
def _main(self, tests, kwargs):
418440
self.ns = self.parse_args(kwargs)
419441

420442
if self.ns.slaveargs is not None:
@@ -473,26 +495,5 @@ def printlist(x, width=70, indent=4):
473495

474496

475497
def main(tests=None, **kwargs):
498+
"""Run the Python suite."""
476499
Regrtest().main(tests=tests, **kwargs)
477-
478-
479-
def main_in_temp_cwd():
480-
"""Run main() in a temporary working directory."""
481-
if sysconfig.is_python_build():
482-
try:
483-
os.mkdir(TEMPDIR)
484-
except FileExistsError:
485-
pass
486-
487-
# Define a writable temp dir that will be used as cwd while running
488-
# the tests. The name of the dir includes the pid to allow parallel
489-
# testing (see the -j option).
490-
test_cwd = 'test_python_{}'.format(os.getpid())
491-
test_cwd = os.path.join(TEMPDIR, test_cwd)
492-
493-
# Run the tests in a context manager that temporarily changes the CWD to a
494-
# temporary and writable directory. If it's not possible to create or
495-
# change the CWD, the original CWD will be used. The original CWD is
496-
# available from support.SAVEDCWD.
497-
with support.temp_cwd(test_cwd, quiet=True):
498-
main()

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
1515

1616

17-
if __name__ == '__main__':
17+
# Alias for backward compatibility (just in case)
18+
main_in_temp_cwd = main
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()

Lib/test/test_importlib/regrtest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"""
99
import importlib
1010
import sys
11-
from test import regrtest
11+
from test import libregrtest
1212

1313
if __name__ == '__main__':
1414
__builtins__.__import__ = importlib.__import__
1515
sys.path_importer_cache.clear()
1616

17-
regrtest.main(quiet=True, verbose2=True)
17+
libregrtest.main(quiet=True, verbose2=True)

PC/testpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
# Add the "test" directory to PYTHONPATH.
2727
sys.path = sys.path + [test]
2828

29-
import regrtest # Standard Python tester.
30-
regrtest.main()
29+
import libregrtest # Standard Python tester.
30+
libregrtest.main()

PCbuild/rt.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if "%1"=="-x64" (set prefix=%pcbuild%amd64\) & shift & goto CheckOpts
4242
if NOT "%1"=="" (set regrtestargs=%regrtestargs% %1) & shift & goto CheckOpts
4343

4444
set exe=%prefix%python%suffix%.exe
45-
set cmd="%exe%" %dashO% -Wd -E -bb "%pcbuild%..\lib\test\regrtest.py" %regrtestargs%
45+
set cmd="%exe%" %dashO% -Wd -E -bb -m test %regrtestargs%
4646
if defined qmode goto Qmode
4747

4848
echo Deleting .pyc/.pyo files ...

0 commit comments

Comments
 (0)