11import argparse
2- import os
2+ import os . path
33import shlex
44import sys
55from test .support import os_helper
6+ from .utils import ALL_RESOURCES , RESOURCE_NAMES
67
78
89USAGE = """\
2728 Additional option details:
2829
2930-r randomizes test execution order. You can use --randseed=int to provide an
30- int seed value for the randomizer; this is useful for reproducing troublesome
31- test orders.
31+ int seed value for the randomizer. The randseed value will be used
32+ to set seeds for all random usages in tests
33+ (including randomizing the tests order if -r is set).
34+ By default we always set random seed, but do not randomize test order.
3235
3336-s On the first invocation of regrtest using -s, the first test file found
3437or the first test file given on the command line is run, and the name of
130133"""
131134
132135
133- ALL_RESOURCES = ('audio' , 'curses' , 'largefile' , 'network' ,
134- 'decimal' , 'cpu' , 'subprocess' , 'urlfetch' , 'gui' , 'walltime' )
135-
136- # Other resources excluded from --use=all:
137- #
138- # - extralagefile (ex: test_zipfile64): really too slow to be enabled
139- # "by default"
140- # - tzdata: while needed to validate fully test_datetime, it makes
141- # test_datetime too slow (15-20 min on some buildbots) and so is disabled by
142- # default (see bpo-30822).
143- RESOURCE_NAMES = ALL_RESOURCES + ('extralargefile' , 'tzdata' )
144-
145-
146136class Namespace (argparse .Namespace ):
147137 def __init__ (self , ** kwargs ) -> None :
138+ self .ci = False
148139 self .testdir = None
149140 self .verbose = 0
150141 self .quiet = False
151142 self .exclude = False
143+ self .cleanup = False
144+ self .wait = False
145+ self .list_cases = False
146+ self .list_tests = False
152147 self .single = False
153148 self .randomize = False
154149 self .fromfile = None
@@ -157,7 +152,7 @@ def __init__(self, **kwargs) -> None:
157152 self .trace = False
158153 self .coverdir = 'coverage'
159154 self .runleaks = False
160- self .huntrleaks = False
155+ self .huntrleaks : tuple [ int , int , str ] | None = None
161156 self .rerun = False
162157 self .verbose3 = False
163158 self .print_slow = False
@@ -170,6 +165,14 @@ def __init__(self, **kwargs) -> None:
170165 self .ignore_tests = None
171166 self .pgo = False
172167 self .pgo_extended = False
168+ self .worker_json = None
169+ self .start = None
170+ self .timeout = None
171+ self .memlimit = None
172+ self .threshold = None
173+ self .fail_rerun = False
174+ self .tempdir = None
175+ self ._add_python_opts = True
173176
174177 super ().__init__ (** kwargs )
175178
@@ -198,19 +201,27 @@ def _create_parser():
198201 # We add help explicitly to control what argument group it renders under.
199202 group .add_argument ('-h' , '--help' , action = 'help' ,
200203 help = 'show this help message and exit' )
201- group .add_argument ('--timeout' , metavar = 'TIMEOUT' , type = float ,
204+ group .add_argument ('--fast-ci' , action = 'store_true' ,
205+ help = 'Fast Continuous Integration (CI) mode used by '
206+ 'GitHub Actions' )
207+ group .add_argument ('--slow-ci' , action = 'store_true' ,
208+ help = 'Slow Continuous Integration (CI) mode used by '
209+ 'buildbot workers' )
210+ group .add_argument ('--timeout' , metavar = 'TIMEOUT' ,
202211 help = 'dump the traceback and exit if a test takes '
203212 'more than TIMEOUT seconds; disabled if TIMEOUT '
204213 'is negative or equals to zero' )
205214 group .add_argument ('--wait' , action = 'store_true' ,
206215 help = 'wait for user input, e.g., allow a debugger '
207216 'to be attached' )
208- group .add_argument ('--worker-args' , metavar = 'ARGS' )
209217 group .add_argument ('-S' , '--start' , metavar = 'START' ,
210218 help = 'the name of the test at which to start.' +
211219 more_details )
212220 group .add_argument ('-p' , '--python' , metavar = 'PYTHON' ,
213221 help = 'Command to run Python test subprocesses with.' )
222+ group .add_argument ('--randseed' , metavar = 'SEED' ,
223+ dest = 'random_seed' , type = int ,
224+ help = 'pass a global random seed' )
214225
215226 group = parser .add_argument_group ('Verbosity' )
216227 group .add_argument ('-v' , '--verbose' , action = 'count' ,
@@ -231,10 +242,6 @@ def _create_parser():
231242 group = parser .add_argument_group ('Selecting tests' )
232243 group .add_argument ('-r' , '--randomize' , action = 'store_true' ,
233244 help = 'randomize test execution order.' + more_details )
234- group .add_argument ('--randseed' , metavar = 'SEED' ,
235- dest = 'random_seed' , type = int ,
236- help = 'pass a random seed to reproduce a previous '
237- 'random run' )
238245 group .add_argument ('-f' , '--fromfile' , metavar = 'FILE' ,
239246 help = 'read names of tests to run from a file.' +
240247 more_details )
@@ -324,6 +331,9 @@ def _create_parser():
324331 help = 'override the working directory for the test run' )
325332 group .add_argument ('--cleanup' , action = 'store_true' ,
326333 help = 'remove old test_python_* directories' )
334+ group .add_argument ('--dont-add-python-opts' , dest = '_add_python_opts' ,
335+ action = 'store_false' ,
336+ help = "internal option, don't use it" )
327337 return parser
328338
329339
@@ -374,7 +384,50 @@ def _parse_args(args, **kwargs):
374384 for arg in ns .args :
375385 if arg .startswith ('-' ):
376386 parser .error ("unrecognized arguments: %s" % arg )
377- sys .exit (1 )
387+
388+ if ns .timeout is not None :
389+ # Support "--timeout=" (no value) so Makefile.pre.pre TESTTIMEOUT
390+ # can be used by "make buildbottest" and "make test".
391+ if ns .timeout != "" :
392+ try :
393+ ns .timeout = float (ns .timeout )
394+ except ValueError :
395+ parser .error (f"invalid timeout value: { ns .timeout !r} " )
396+ else :
397+ ns .timeout = None
398+
399+ # Continuous Integration (CI): common options for fast/slow CI modes
400+ if ns .slow_ci or ns .fast_ci :
401+ # Similar to options:
402+ #
403+ # -j0 --randomize --fail-env-changed --fail-rerun --rerun
404+ # --slowest --verbose3
405+ if ns .use_mp is None :
406+ ns .use_mp = 0
407+ ns .randomize = True
408+ ns .fail_env_changed = True
409+ ns .fail_rerun = True
410+ if ns .python is None :
411+ ns .rerun = True
412+ ns .print_slow = True
413+ ns .verbose3 = True
414+ else :
415+ ns ._add_python_opts = False
416+
417+ # When both --slow-ci and --fast-ci options are present,
418+ # --slow-ci has the priority
419+ if ns .slow_ci :
420+ # Similar to: -u "all" --timeout=1200
421+ if not ns .use :
422+ ns .use = [['all' ]]
423+ if ns .timeout is None :
424+ ns .timeout = 1200 # 20 minutes
425+ elif ns .fast_ci :
426+ # Similar to: -u "all,-cpu" --timeout=600
427+ if not ns .use :
428+ ns .use = [['all' , '-cpu' ]]
429+ if ns .timeout is None :
430+ ns .timeout = 600 # 10 minutes
378431
379432 if ns .single and ns .fromfile :
380433 parser .error ("-s and -f don't go together!" )
@@ -401,10 +454,6 @@ def _parse_args(args, **kwargs):
401454 if ns .timeout is not None :
402455 if ns .timeout <= 0 :
403456 ns .timeout = None
404- if ns .use_mp is not None :
405- if ns .use_mp <= 0 :
406- # Use all cores + extras for tests that like to sleep
407- ns .use_mp = 2 + (os .cpu_count () or 1 )
408457 if ns .use :
409458 for a in ns .use :
410459 for r in a :
@@ -448,4 +497,13 @@ def _parse_args(args, **kwargs):
448497 # --forever implies --failfast
449498 ns .failfast = True
450499
500+ if ns .huntrleaks :
501+ warmup , repetitions , _ = ns .huntrleaks
502+ if warmup < 1 or repetitions < 1 :
503+ msg = ("Invalid values for the --huntrleaks/-R parameters. The "
504+ "number of warmups and repetitions must be at least 1 "
505+ "each (1:1)." )
506+ print (msg , file = sys .stderr , flush = True )
507+ sys .exit (2 )
508+
451509 return ns
0 commit comments