1111import unittest
1212from test .libregrtest .cmdline import _parse_args , Namespace
1313from test .libregrtest .runtest import (
14- findtests , split_test_packages , runtest , abs_module_name ,
14+ findtests , split_test_packages , run_single_test , abs_module_name ,
1515 PROGRESS_MIN_TIME , State , RunTests , TestResult ,
1616 FilterTuple , FilterDict , TestList )
17- from test .libregrtest .setup import setup_tests
17+ from test .libregrtest .setup import setup_tests , setup_test_dir
1818from test .libregrtest .pgo import setup_pgo_tests
1919from test .libregrtest .utils import (strip_py_suffix , count , format_duration ,
2020 printlist , get_build_info )
@@ -64,11 +64,11 @@ def __init__(self, ns: Namespace):
6464 self .ns : Namespace = ns
6565
6666 # 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
7272
7373 # Select tests
7474 if ns .match_tests :
@@ -79,14 +79,19 @@ def __init__(self, ns: Namespace):
7979 self .ignore_tests : FilterTuple = tuple (ns .ignore_tests )
8080 else :
8181 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
8585
8686 # 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
9095
9196 # tests
9297 self .tests = []
@@ -196,21 +201,19 @@ def log(self, line=''):
196201
197202 def display_progress (self , test_index , text ):
198203 quiet = self .ns .quiet
199- pgo = self .ns .pgo
200204 if quiet :
201205 return
202206
203207 # "[ 51/405/1] test_tcl passed"
204208 line = f"{ test_index :{self .test_count_width }} { self .test_count_text } "
205209 fails = len (self .bad ) + len (self .environment_changed )
206- if fails and not pgo :
210+ if fails and not self . pgo :
207211 line = f"{ line } /{ fails } "
208212 self .log (f"[{ line } ] { text } " )
209213
210214 def find_tests (self ):
211215 ns = self .ns
212216 single = ns .single
213- pgo = ns .pgo
214217 test_dir = ns .testdir
215218
216219 if single :
@@ -237,7 +240,7 @@ def find_tests(self):
237240
238241 strip_py_suffix (self .tests )
239242
240- if pgo :
243+ if self . pgo :
241244 # add default PGO tests if no tests are specified
242245 setup_pgo_tests (ns )
243246
@@ -329,8 +332,6 @@ def _rerun_failed_tests(self, need_rerun, runtests: RunTests):
329332 # Configure the runner to re-run tests
330333 ns = self .ns
331334 ns .verbose = True
332- ns .failfast = False
333- ns .verbose3 = False
334335 if ns .use_mp is None :
335336 ns .use_mp = 1
336337
@@ -345,12 +346,16 @@ def _rerun_failed_tests(self, need_rerun, runtests: RunTests):
345346
346347 # Re-run failed tests
347348 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 )
352356 self .set_tests (runtests )
353357 self ._run_tests_mp (runtests )
358+ return runtests
354359
355360 def rerun_failed_tests (self , need_rerun , runtests : RunTests ):
356361 if self .ns .python :
@@ -364,16 +369,16 @@ def rerun_failed_tests(self, need_rerun, runtests: RunTests):
364369 self .first_state = self .get_tests_state ()
365370
366371 print ()
367- self ._rerun_failed_tests (need_rerun , runtests )
372+ rerun_runtests = self ._rerun_failed_tests (need_rerun , runtests )
368373
369374 if self .bad :
370375 print (count (len (self .bad ), 'test' ), "failed again:" )
371376 printlist (self .bad )
372377
373- self .display_result ()
378+ self .display_result (rerun_runtests )
374379
375- def display_result (self ):
376- pgo = self . ns .pgo
380+ def display_result (self , runtests ):
381+ pgo = runtests .pgo
377382 quiet = self .ns .quiet
378383 print_slow = self .ns .print_slow
379384
@@ -444,12 +449,12 @@ def run_test(self, test_name: str, runtests: RunTests, tracer):
444449 if tracer is not None :
445450 # If we're tracing code coverage, then we don't exit with status
446451 # 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)' )
448453 ns = dict (locals ())
449454 tracer .runctx (cmd , globals = globals (), locals = ns )
450455 result = ns ['result' ]
451456 else :
452- result = runtest ( self .ns , test_name )
457+ result = run_single_test ( test_name , runtests , self .ns )
453458
454459 self .accumulate_result (result )
455460
@@ -458,9 +463,7 @@ def run_test(self, test_name: str, runtests: RunTests, tracer):
458463 def run_tests_sequentially (self , runtests ):
459464 ns = self .ns
460465 coverage = ns .trace
461- fail_fast = ns .failfast
462466 fail_env_changed = ns .fail_env_changed
463- timeout = ns .timeout
464467
465468 if coverage :
466469 import trace
@@ -471,8 +474,8 @@ def run_tests_sequentially(self, runtests):
471474 save_modules = sys .modules .keys ()
472475
473476 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 )
476479 self .log (msg )
477480
478481 previous_test = None
@@ -492,7 +495,7 @@ def run_tests_sequentially(self, runtests):
492495 if module not in save_modules and module .startswith ("test." ):
493496 support .unload (module )
494497
495- if result .must_stop (fail_fast , fail_env_changed ):
498+ if result .must_stop (self . fail_fast , fail_env_changed ):
496499 break
497500
498501 previous_test = str (result )
@@ -850,16 +853,28 @@ def action_run_tests(self):
850853
851854 # For a partial run, we do not need to clutter the output.
852855 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
854857 or self .tests or self .ns .args )):
855858 self .display_header ()
856859
857860 if self .randomize :
858861 print ("Using random seed" , self .random_seed )
859862
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+
861876 tracer = self .run_tests (runtests )
862- self .display_result ()
877+ self .display_result (runtests )
863878
864879 need_rerun = self .need_rerun
865880 if self .ns .rerun and need_rerun :
@@ -877,7 +892,7 @@ def _main(self):
877892 if self .want_wait :
878893 input ("Press any key to continue..." )
879894
880- setup_tests (self .ns )
895+ setup_test_dir (self .ns . testdir )
881896 self .find_tests ()
882897
883898 exitcode = 0
0 commit comments