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,8 +152,8 @@ def __init__(self, **kwargs) -> None:
157
152
self .trace = False
158
153
self .coverdir = 'coverage'
159
154
self .runleaks = False
160
- self .huntrleaks = False
161
- self .verbose2 = False
155
+ self .huntrleaks : tuple [ int , int , str ] | None = None
156
+ self .rerun = False
162
157
self .verbose3 = False
163
158
self .print_slow = False
164
159
self .random_seed = None
@@ -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,25 +201,35 @@ 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' ,
217
228
help = 'run tests in verbose mode with output to stdout' )
218
- group .add_argument ('-w' , '--verbose2 ' , action = 'store_true' ,
229
+ group .add_argument ('-w' , '--rerun ' , action = 'store_true' ,
219
230
help = 're-run failed tests in verbose mode' )
231
+ group .add_argument ('--verbose2' , action = 'store_true' , dest = 'rerun' ,
232
+ help = 'deprecated alias to --rerun' )
220
233
group .add_argument ('-W' , '--verbose3' , action = 'store_true' ,
221
234
help = 'display test output on failure' )
222
235
group .add_argument ('-q' , '--quiet' , action = 'store_true' ,
@@ -229,10 +242,6 @@ def _create_parser():
229
242
group = parser .add_argument_group ('Selecting tests' )
230
243
group .add_argument ('-r' , '--randomize' , action = 'store_true' ,
231
244
help = 'randomize test execution order.' + more_details )
232
- group .add_argument ('--randseed' , metavar = 'SEED' ,
233
- dest = 'random_seed' , type = int ,
234
- help = 'pass a random seed to reproduce a previous '
235
- 'random run' )
236
245
group .add_argument ('-f' , '--fromfile' , metavar = 'FILE' ,
237
246
help = 'read names of tests to run from a file.' +
238
247
more_details )
@@ -311,6 +320,9 @@ def _create_parser():
311
320
group .add_argument ('--fail-env-changed' , action = 'store_true' ,
312
321
help = 'if a test file alters the environment, mark '
313
322
'the test as failed' )
323
+ group .add_argument ('--fail-rerun' , action = 'store_true' ,
324
+ help = 'if a test failed and then passed when re-run, '
325
+ 'mark the tests as failed' )
314
326
315
327
group .add_argument ('--junit-xml' , dest = 'xmlpath' , metavar = 'FILENAME' ,
316
328
help = 'writes JUnit-style XML results to the specified '
@@ -319,6 +331,9 @@ def _create_parser():
319
331
help = 'override the working directory for the test run' )
320
332
group .add_argument ('--cleanup' , action = 'store_true' ,
321
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" )
322
337
return parser
323
338
324
339
@@ -369,7 +384,50 @@ def _parse_args(args, **kwargs):
369
384
for arg in ns .args :
370
385
if arg .startswith ('-' ):
371
386
parser .error ("unrecognized arguments: %s" % arg )
372
- 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
373
431
374
432
if ns .single and ns .fromfile :
375
433
parser .error ("-s and -f don't go together!" )
@@ -382,7 +440,7 @@ def _parse_args(args, **kwargs):
382
440
ns .python = shlex .split (ns .python )
383
441
if ns .failfast and not (ns .verbose or ns .verbose3 ):
384
442
parser .error ("-G/--failfast needs either -v or -W" )
385
- if ns .pgo and (ns .verbose or ns .verbose2 or ns .verbose3 ):
443
+ if ns .pgo and (ns .verbose or ns .rerun or ns .verbose3 ):
386
444
parser .error ("--pgo/-v don't go together!" )
387
445
if ns .pgo_extended :
388
446
ns .pgo = True # pgo_extended implies pgo
@@ -396,10 +454,6 @@ def _parse_args(args, **kwargs):
396
454
if ns .timeout is not None :
397
455
if ns .timeout <= 0 :
398
456
ns .timeout = None
399
- if ns .use_mp is not None :
400
- if ns .use_mp <= 0 :
401
- # Use all cores + extras for tests that like to sleep
402
- ns .use_mp = 2 + (os .cpu_count () or 1 )
403
457
if ns .use :
404
458
for a in ns .use :
405
459
for r in a :
@@ -443,4 +497,13 @@ def _parse_args(args, **kwargs):
443
497
# --forever implies --failfast
444
498
ns .failfast = True
445
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
+
446
509
return ns
0 commit comments