11
11
import unittest
12
12
from test .libregrtest .cmdline import _parse_args , Namespace
13
13
from test .libregrtest .runtest import (
14
- findtests , split_test_packages , runtest , abs_module_name ,
14
+ findtests , split_test_packages , run_single_test , abs_module_name ,
15
15
PROGRESS_MIN_TIME , State , RunTests , TestResult ,
16
16
FilterTuple , FilterDict , TestList )
17
- from test .libregrtest .setup import setup_tests
17
+ from test .libregrtest .setup import setup_tests , setup_test_dir
18
18
from test .libregrtest .pgo import setup_pgo_tests
19
19
from test .libregrtest .utils import (strip_py_suffix , count , format_duration ,
20
20
printlist , get_build_info )
@@ -64,11 +64,11 @@ def __init__(self, ns: Namespace):
64
64
self .ns : Namespace = ns
65
65
66
66
# Actions
67
- self .want_header = ns .header
68
- self .want_list_tests = ns .list_tests
69
- self .want_list_cases = ns .list_cases
70
- self .want_wait = ns .wait
71
- self .want_cleanup = ns .cleanup
67
+ self .want_header : bool = ns .header
68
+ self .want_list_tests : bool = ns .list_tests
69
+ self .want_list_cases : bool = ns .list_cases
70
+ self .want_wait : bool = ns .wait
71
+ self .want_cleanup : bool = ns .cleanup
72
72
73
73
# Select tests
74
74
if ns .match_tests :
@@ -79,14 +79,19 @@ def __init__(self, ns: Namespace):
79
79
self .ignore_tests : FilterTuple = tuple (ns .ignore_tests )
80
80
else :
81
81
self .ignore_tests = None
82
- self .exclude = ns .exclude
83
- self .fromfile = ns .fromfile
84
- self .starting_test = ns .start
82
+ self .exclude : bool = ns .exclude
83
+ self .fromfile : str | None = ns .fromfile
84
+ self .starting_test : str | None = ns .start
85
85
86
86
# Options to run tests
87
- self .forever = ns .forever
88
- self .randomize = ns .randomize
89
- self .random_seed = ns .random_seed
87
+ self .fail_fast : bool = ns .failfast
88
+ self .forever : bool = ns .forever
89
+ self .randomize : bool = ns .randomize
90
+ self .random_seed : int | None = ns .random_seed
91
+ self .pgo : bool = ns .pgo
92
+ self .pgo_extended : bool = ns .pgo_extended
93
+ self .output_on_failure : bool = ns .verbose3
94
+ self .timeout : float | None = ns .timeout
90
95
91
96
# tests
92
97
self .tests = []
@@ -196,21 +201,19 @@ def log(self, line=''):
196
201
197
202
def display_progress (self , test_index , text ):
198
203
quiet = self .ns .quiet
199
- pgo = self .ns .pgo
200
204
if quiet :
201
205
return
202
206
203
207
# "[ 51/405/1] test_tcl passed"
204
208
line = f"{ test_index :{self .test_count_width }} { self .test_count_text } "
205
209
fails = len (self .bad ) + len (self .environment_changed )
206
- if fails and not pgo :
210
+ if fails and not self . pgo :
207
211
line = f"{ line } /{ fails } "
208
212
self .log (f"[{ line } ] { text } " )
209
213
210
214
def find_tests (self ):
211
215
ns = self .ns
212
216
single = ns .single
213
- pgo = ns .pgo
214
217
test_dir = ns .testdir
215
218
216
219
if single :
@@ -237,7 +240,7 @@ def find_tests(self):
237
240
238
241
strip_py_suffix (self .tests )
239
242
240
- if pgo :
243
+ if self . pgo :
241
244
# add default PGO tests if no tests are specified
242
245
setup_pgo_tests (ns )
243
246
@@ -329,8 +332,6 @@ def _rerun_failed_tests(self, need_rerun, runtests: RunTests):
329
332
# Configure the runner to re-run tests
330
333
ns = self .ns
331
334
ns .verbose = True
332
- ns .failfast = False
333
- ns .verbose3 = False
334
335
if ns .use_mp is None :
335
336
ns .use_mp = 1
336
337
@@ -345,12 +346,16 @@ def _rerun_failed_tests(self, need_rerun, runtests: RunTests):
345
346
346
347
# Re-run failed tests
347
348
self .log (f"Re-running { len (tests )} failed tests in verbose mode in subprocesses" )
348
- runtests = runtests .copy (tests = tuple (tests ),
349
- match_tests_dict = match_tests_dict ,
350
- rerun = True ,
351
- forever = False )
349
+ runtests = runtests .copy (
350
+ tests = tuple (tests ),
351
+ rerun = True ,
352
+ forever = False ,
353
+ fail_fast = False ,
354
+ match_tests_dict = match_tests_dict ,
355
+ output_on_failure = False )
352
356
self .set_tests (runtests )
353
357
self ._run_tests_mp (runtests )
358
+ return runtests
354
359
355
360
def rerun_failed_tests (self , need_rerun , runtests : RunTests ):
356
361
if self .ns .python :
@@ -364,16 +369,16 @@ def rerun_failed_tests(self, need_rerun, runtests: RunTests):
364
369
self .first_state = self .get_tests_state ()
365
370
366
371
print ()
367
- self ._rerun_failed_tests (need_rerun , runtests )
372
+ rerun_runtests = self ._rerun_failed_tests (need_rerun , runtests )
368
373
369
374
if self .bad :
370
375
print (count (len (self .bad ), 'test' ), "failed again:" )
371
376
printlist (self .bad )
372
377
373
- self .display_result ()
378
+ self .display_result (rerun_runtests )
374
379
375
- def display_result (self ):
376
- pgo = self . ns .pgo
380
+ def display_result (self , runtests ):
381
+ pgo = runtests .pgo
377
382
quiet = self .ns .quiet
378
383
print_slow = self .ns .print_slow
379
384
@@ -444,12 +449,12 @@ def run_test(self, test_name: str, runtests: RunTests, tracer):
444
449
if tracer is not None :
445
450
# If we're tracing code coverage, then we don't exit with status
446
451
# if on a false return value from main.
447
- cmd = ('result = runtest( self.ns, test_name )' )
452
+ cmd = ('result = run_single_test(test_name, runtests, self.ns)' )
448
453
ns = dict (locals ())
449
454
tracer .runctx (cmd , globals = globals (), locals = ns )
450
455
result = ns ['result' ]
451
456
else :
452
- result = runtest ( self .ns , test_name )
457
+ result = run_single_test ( test_name , runtests , self .ns )
453
458
454
459
self .accumulate_result (result )
455
460
@@ -458,9 +463,7 @@ def run_test(self, test_name: str, runtests: RunTests, tracer):
458
463
def run_tests_sequentially (self , runtests ):
459
464
ns = self .ns
460
465
coverage = ns .trace
461
- fail_fast = ns .failfast
462
466
fail_env_changed = ns .fail_env_changed
463
- timeout = ns .timeout
464
467
465
468
if coverage :
466
469
import trace
@@ -471,8 +474,8 @@ def run_tests_sequentially(self, runtests):
471
474
save_modules = sys .modules .keys ()
472
475
473
476
msg = "Run tests sequentially"
474
- if timeout :
475
- msg += " (timeout: %s)" % format_duration (timeout )
477
+ if runtests . timeout :
478
+ msg += " (timeout: %s)" % format_duration (runtests . timeout )
476
479
self .log (msg )
477
480
478
481
previous_test = None
@@ -492,7 +495,7 @@ def run_tests_sequentially(self, runtests):
492
495
if module not in save_modules and module .startswith ("test." ):
493
496
support .unload (module )
494
497
495
- if result .must_stop (fail_fast , fail_env_changed ):
498
+ if result .must_stop (self . fail_fast , fail_env_changed ):
496
499
break
497
500
498
501
previous_test = str (result )
@@ -850,16 +853,28 @@ def action_run_tests(self):
850
853
851
854
# For a partial run, we do not need to clutter the output.
852
855
if (self .want_header
853
- or not (self .ns . pgo or self .ns .quiet or self .ns .single
856
+ or not (self .pgo or self .ns .quiet or self .ns .single
854
857
or self .tests or self .ns .args )):
855
858
self .display_header ()
856
859
857
860
if self .randomize :
858
861
print ("Using random seed" , self .random_seed )
859
862
860
- runtests = RunTests (tuple (self .selected ), forever = self .forever )
863
+ runtests = RunTests (
864
+ tuple (self .selected ),
865
+ fail_fast = self .fail_fast ,
866
+ match_tests = self .match_tests ,
867
+ ignore_tests = self .ignore_tests ,
868
+ forever = self .forever ,
869
+ pgo = self .pgo ,
870
+ pgo_extended = self .pgo_extended ,
871
+ output_on_failure = self .output_on_failure ,
872
+ timeout = self .timeout )
873
+
874
+ setup_tests (runtests , self .ns )
875
+
861
876
tracer = self .run_tests (runtests )
862
- self .display_result ()
877
+ self .display_result (runtests )
863
878
864
879
need_rerun = self .need_rerun
865
880
if self .ns .rerun and need_rerun :
@@ -877,7 +892,7 @@ def _main(self):
877
892
if self .want_wait :
878
893
input ("Press any key to continue..." )
879
894
880
- setup_tests (self .ns )
895
+ setup_test_dir (self .ns . testdir )
881
896
self .find_tests ()
882
897
883
898
exitcode = 0
0 commit comments