1
1
import argparse
2
- import os
2
+ import os . path
3
3
import shlex
4
4
import sys
5
5
from test .support import os_helper
6
+ from .utils import ALL_RESOURCES , RESOURCE_NAMES
6
7
7
8
8
9
USAGE = """\
27
28
Additional option details:
28
29
29
30
-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.
32
35
33
36
-s On the first invocation of regrtest using -s, the first test file found
34
37
or the first test file given on the command line is run, and the name of
130
133
"""
131
134
132
135
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
-
146
136
class Namespace (argparse .Namespace ):
147
137
def __init__ (self , ** kwargs ) -> None :
138
+ self .ci = False
148
139
self .testdir = None
149
140
self .verbose = 0
150
141
self .quiet = False
151
142
self .exclude = False
143
+ self .cleanup = False
144
+ self .wait = False
145
+ self .list_cases = False
146
+ self .list_tests = False
152
147
self .single = False
153
148
self .randomize = False
154
149
self .fromfile = None
@@ -157,7 +152,7 @@ def __init__(self, **kwargs) -> None:
157
152
self .trace = False
158
153
self .coverdir = 'coverage'
159
154
self .runleaks = False
160
- self .huntrleaks = False
155
+ self .huntrleaks : tuple [ int , int , str ] | None = None
161
156
self .rerun = False
162
157
self .verbose3 = False
163
158
self .print_slow = False
@@ -170,6 +165,14 @@ def __init__(self, **kwargs) -> None:
170
165
self .ignore_tests = None
171
166
self .pgo = False
172
167
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
173
176
174
177
super ().__init__ (** kwargs )
175
178
@@ -198,19 +201,27 @@ def _create_parser():
198
201
# We add help explicitly to control what argument group it renders under.
199
202
group .add_argument ('-h' , '--help' , action = 'help' ,
200
203
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' ,
202
211
help = 'dump the traceback and exit if a test takes '
203
212
'more than TIMEOUT seconds; disabled if TIMEOUT '
204
213
'is negative or equals to zero' )
205
214
group .add_argument ('--wait' , action = 'store_true' ,
206
215
help = 'wait for user input, e.g., allow a debugger '
207
216
'to be attached' )
208
- group .add_argument ('--worker-args' , metavar = 'ARGS' )
209
217
group .add_argument ('-S' , '--start' , metavar = 'START' ,
210
218
help = 'the name of the test at which to start.' +
211
219
more_details )
212
220
group .add_argument ('-p' , '--python' , metavar = 'PYTHON' ,
213
221
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' )
214
225
215
226
group = parser .add_argument_group ('Verbosity' )
216
227
group .add_argument ('-v' , '--verbose' , action = 'count' ,
@@ -231,10 +242,6 @@ def _create_parser():
231
242
group = parser .add_argument_group ('Selecting tests' )
232
243
group .add_argument ('-r' , '--randomize' , action = 'store_true' ,
233
244
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' )
238
245
group .add_argument ('-f' , '--fromfile' , metavar = 'FILE' ,
239
246
help = 'read names of tests to run from a file.' +
240
247
more_details )
@@ -324,6 +331,9 @@ def _create_parser():
324
331
help = 'override the working directory for the test run' )
325
332
group .add_argument ('--cleanup' , action = 'store_true' ,
326
333
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" )
327
337
return parser
328
338
329
339
@@ -374,7 +384,50 @@ def _parse_args(args, **kwargs):
374
384
for arg in ns .args :
375
385
if arg .startswith ('-' ):
376
386
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
378
431
379
432
if ns .single and ns .fromfile :
380
433
parser .error ("-s and -f don't go together!" )
@@ -401,10 +454,6 @@ def _parse_args(args, **kwargs):
401
454
if ns .timeout is not None :
402
455
if ns .timeout <= 0 :
403
456
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 )
408
457
if ns .use :
409
458
for a in ns .use :
410
459
for r in a :
@@ -448,4 +497,13 @@ def _parse_args(args, **kwargs):
448
497
# --forever implies --failfast
449
498
ns .failfast = True
450
499
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
+
451
509
return ns
0 commit comments