Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c01d16

Browse files
committed
Issue #11651: Move options for running tests into a Python script.
This will be particularly useful to Windows users. run_tests.py originally written by Brett Cannon.
1 parent b0fa4b8 commit 3c01d16

4 files changed

Lines changed: 75 additions & 16 deletions

File tree

Lib/test/regrtest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133
134134
all - Enable all special resources.
135135
136+
none - Disable all special resources (this is the default).
137+
136138
audio - Tests that use the audio device. (There are known
137139
cases of broken audio drivers that can crash Python or
138140
even the Linux kernel.)
@@ -387,6 +389,9 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
387389
if r == 'all':
388390
use_resources[:] = RESOURCE_NAMES
389391
continue
392+
if r == 'none':
393+
del use_resources[:]
394+
continue
390395
remove = False
391396
if r[0] == '-':
392397
remove = True
@@ -424,6 +429,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
424429
use_mp = 2 + multiprocessing.cpu_count()
425430
except (ImportError, NotImplementedError):
426431
use_mp = 3
432+
if use_mp == 1:
433+
use_mp = None
427434
elif o == '--header':
428435
header = True
429436
elif o == '--slaveargs':

Makefile.pre.in

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -747,14 +747,15 @@ $(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS)
747747

748748
######################################################################
749749

750-
# Run a basic set of regression tests.
751-
# This excludes some tests that are particularly resource-intensive.
752750
TESTOPTS= $(EXTRATESTOPTS)
753-
TESTPROG= $(srcdir)/Lib/test/regrtest.py
754-
TESTPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) -Wd -E -bb $(TESTPYTHONOPTS)
751+
TESTPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) $(TESTPYTHONOPTS)
752+
TESTRUNNER= $(TESTPYTHON) $(srcdir)/Tools/scripts/run_tests.py
755753
TESTTIMEOUT= 3600
754+
755+
# Run a basic set of regression tests.
756+
# This excludes some tests that are particularly resource-intensive.
756757
test: all platform
757-
$(TESTPYTHON) $(TESTPROG) -j0 $(TESTOPTS)
758+
$(TESTRUNNER) $(TESTOPTS)
758759

759760
# Run the full test suite twice - once without .pyc files, and once with.
760761
# In the past, we've had problems where bugs in the marshalling or
@@ -765,10 +766,10 @@ test: all platform
765766
# sample data.
766767
testall: all platform
767768
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
768-
$(TESTPYTHON) $(srcdir)/Lib/compileall.py
769+
$(TESTPYTHON) -E $(srcdir)/Lib/compileall.py
769770
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
770-
-$(TESTPYTHON) $(TESTPROG) -j0 -uall $(TESTOPTS)
771-
$(TESTPYTHON) $(TESTPROG) -j0 -uall $(TESTOPTS)
771+
-$(TESTRUNNER) -u all $(TESTOPTS)
772+
$(TESTRUNNER) -u all $(TESTOPTS)
772773

773774
# Run the test suite for both architectures in a Universal build on OSX.
774775
# Must be run on an Intel box.
@@ -777,25 +778,24 @@ testuniversal: all platform
777778
echo "This can only be used on OSX/i386" ;\
778779
exit 1 ;\
779780
fi
780-
$(TESTPYTHON) $(TESTPROG) -j0 -uall $(TESTOPTS)
781-
$(RUNSHARED) /usr/libexec/oah/translate ./$(BUILDPYTHON) -E $(TESTPROG) -j0 -uall $(TESTOPTS)
781+
$(TESTRUNNER) -u all $(TESTOPTS)
782+
$(RUNSHARED) /usr/libexec/oah/translate \
783+
./$(BUILDPYTHON) -E -m test -j 0 -u all $(TESTOPTS)
782784

783-
# Like testall, but with only one pass.
785+
# Like testall, but with only one pass and without multiple processes.
784786
# Run an optional script to include information about the build environment.
785787
buildbottest: all platform
786788
-@if which pybuildbot.identify >/dev/null 2>&1; then \
787789
pybuildbot.identify "CC='$(CC)'" "CXX='$(CXX)'"; \
788790
fi
789-
$(TESTPYTHON) $(TESTPROG) -uall -rwW --timeout=$(TESTTIMEOUT) $(TESTOPTS)
791+
$(TESTRUNNER) -j 1 -u all -W --timeout=$(TESTTIMEOUT) $(TESTOPTS)
790792

791793
QUICKTESTOPTS= $(TESTOPTS) -x test_subprocess test_io test_lib2to3 \
792794
test_multibytecodec test_urllib2_localnet test_itertools \
793795
test_multiprocessing test_mailbox test_socket test_poll \
794-
test_select test_zipfile
796+
test_select test_zipfile test_concurrent_futures
795797
quicktest: all platform
796-
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
797-
-$(TESTPYTHON) $(TESTPROG) -j0 $(QUICKTESTOPTS)
798-
$(TESTPYTHON) $(TESTPROG) -j0 $(QUICKTESTOPTS)
798+
$(TESTRUNNER) $(QUICKTESTOPTS)
799799

800800

801801
install: altinstall bininstall

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,13 @@ Extension Modules
11471147
Tests
11481148
-----
11491149

1150+
- Issue #11651: Improve the Makefile test targets to run more of the test suite
1151+
more quickly. The --multiprocess option is now enabled by default, reducing
1152+
the amount of time needed to run the tests. "make test" and "make quicktest"
1153+
now include some resource-intensive tests, but no longer run the test suite
1154+
twice to check for bugs in .pyc generation. Tools/scripts/run_test.py provides
1155+
as an easy platform-independent way to run test suite with sensible defaults.
1156+
11501157
- Issue #12331: The test suite for the packaging module can now run from an
11511158
installed Python.
11521159

Tools/scripts/run_tests.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Run Python's test suite in a fast, rigorous way.
2+
3+
The defaults are meant to be thorough but to skip certain resources are not
4+
used (by default) which can consume a lot of time and resources (e.g.,
5+
largefile) or can be distracting (e.g., audio and gui). These defaults
6+
can be overridden by simply passing a -u option to this script.
7+
8+
"""
9+
10+
import os
11+
import sys
12+
import test.support
13+
14+
15+
def is_multiprocess_flag(arg):
16+
return arg.startswith('-j') or arg.startswith('--multiprocess')
17+
18+
19+
def is_resource_use_flag(arg):
20+
return arg.startswith('-u') or arg.startswith('--use')
21+
22+
23+
def main(regrtest_args):
24+
args = [sys.executable,
25+
'-W', 'default', # Warnings set to 'default'
26+
'-bb', # Warnings about bytes/bytearray
27+
'-E', # Ignore environment variables
28+
]
29+
# Allow user-specified interpreter options to override our defaults.
30+
args.extend(test.support.args_from_interpreter_flags())
31+
args.extend(['-m', 'test', # Run the test suite
32+
'-r', # Randomize test order
33+
'-w', # Re-run failed tests in verbose mode
34+
])
35+
if not any(is_multiprocess_flag(arg) for arg in regrtest_args):
36+
args.extend(['-j', '0']) # Use all CPU cores
37+
if not any(is_resource_use_flag(arg) for arg in regrtest_args):
38+
args.extend(['-u', 'all,-largefile,-audio,-gui'])
39+
args.extend(regrtest_args)
40+
print(' '.join(args))
41+
os.execv(sys.executable, args)
42+
43+
44+
if __name__ == '__main__':
45+
main(sys.argv[1:])

0 commit comments

Comments
 (0)