12
12
from test .libregrtest .cmdline import _parse_args , Namespace
13
13
from test .libregrtest .runtest import (
14
14
findtests , split_test_packages , run_single_test , abs_module_name ,
15
- PROGRESS_MIN_TIME , State , RunTests , TestResult ,
15
+ PROGRESS_MIN_TIME , State , RunTests , TestResult , HuntRefleak ,
16
16
FilterTuple , FilterDict , TestList )
17
17
from test .libregrtest .setup import setup_tests , setup_test_dir
18
18
from test .libregrtest .pgo import setup_pgo_tests
@@ -92,6 +92,14 @@ def __init__(self, ns: Namespace):
92
92
self .pgo_extended : bool = ns .pgo_extended
93
93
self .output_on_failure : bool = ns .verbose3
94
94
self .timeout : float | None = ns .timeout
95
+ self .verbose : bool = ns .verbose
96
+ self .quiet : bool = ns .quiet
97
+ if ns .huntrleaks :
98
+ self .hunt_refleak : HuntRefleak = HuntRefleak (* ns .huntrleaks )
99
+ else :
100
+ self .hunt_refleak = None
101
+ self .test_dir : str | None = ns .testdir
102
+ self .junit_filename : str | None = ns .xmlpath
95
103
96
104
# tests
97
105
self .tests = []
@@ -200,8 +208,7 @@ def log(self, line=''):
200
208
print (line , flush = True )
201
209
202
210
def display_progress (self , test_index , text ):
203
- quiet = self .ns .quiet
204
- if quiet :
211
+ if self .quiet :
205
212
return
206
213
207
214
# "[ 51/405/1] test_tcl passed"
@@ -214,7 +221,6 @@ def display_progress(self, test_index, text):
214
221
def find_tests (self ):
215
222
ns = self .ns
216
223
single = ns .single
217
- test_dir = ns .testdir
218
224
219
225
if single :
220
226
self .next_single_filename = os .path .join (self .tmp_dir , 'pynexttest' )
@@ -250,7 +256,8 @@ def find_tests(self):
250
256
exclude_tests .add (arg )
251
257
ns .args = []
252
258
253
- alltests = findtests (testdir = test_dir , exclude = exclude_tests )
259
+ alltests = findtests (testdir = self .test_dir ,
260
+ exclude = exclude_tests )
254
261
255
262
if not self .fromfile :
256
263
self .selected = self .tests or ns .args
@@ -298,14 +305,12 @@ def _list_cases(self, suite):
298
305
print (test .id ())
299
306
300
307
def list_cases (self ):
301
- ns = self .ns
302
- test_dir = ns .testdir
303
308
support .verbose = False
304
309
support .set_match_tests (self .match_tests , self .ignore_tests )
305
310
306
311
skipped = []
307
312
for test_name in self .selected :
308
- module_name = abs_module_name (test_name , test_dir )
313
+ module_name = abs_module_name (test_name , self . test_dir )
309
314
try :
310
315
suite = unittest .defaultTestLoader .loadTestsFromName (module_name )
311
316
self ._list_cases (suite )
@@ -331,7 +336,6 @@ def get_rerun_match(self, rerun_list) -> FilterDict:
331
336
def _rerun_failed_tests (self , need_rerun , runtests : RunTests ):
332
337
# Configure the runner to re-run tests
333
338
ns = self .ns
334
- ns .verbose = True
335
339
if ns .use_mp is None :
336
340
ns .use_mp = 1
337
341
@@ -349,6 +353,7 @@ def _rerun_failed_tests(self, need_rerun, runtests: RunTests):
349
353
runtests = runtests .copy (
350
354
tests = tuple (tests ),
351
355
rerun = True ,
356
+ verbose = True ,
352
357
forever = False ,
353
358
fail_fast = False ,
354
359
match_tests_dict = match_tests_dict ,
@@ -379,7 +384,6 @@ def rerun_failed_tests(self, need_rerun, runtests: RunTests):
379
384
380
385
def display_result (self , runtests ):
381
386
pgo = runtests .pgo
382
- quiet = self .ns .quiet
383
387
print_slow = self .ns .print_slow
384
388
385
389
# If running the test suite for PGO then no one cares about results.
@@ -398,7 +402,7 @@ def display_result(self, runtests):
398
402
print (count (len (omitted ), "test" ), "omitted:" )
399
403
printlist (omitted )
400
404
401
- if self .good and not quiet :
405
+ if self .good and not self . quiet :
402
406
print ()
403
407
if (not self .bad
404
408
and not self .skipped
@@ -425,12 +429,12 @@ def display_result(self, runtests):
425
429
count (len (self .environment_changed ), "test" )))
426
430
printlist (self .environment_changed )
427
431
428
- if self .skipped and not quiet :
432
+ if self .skipped and not self . quiet :
429
433
print ()
430
434
print (count (len (self .skipped ), "test" ), "skipped:" )
431
435
printlist (self .skipped )
432
436
433
- if self .resource_denied and not quiet :
437
+ if self .resource_denied and not self . quiet :
434
438
print ()
435
439
print (count (len (self .resource_denied ), "test" ), "skipped (resource denied):" )
436
440
printlist (self .resource_denied )
@@ -684,7 +688,7 @@ def display_summary(self):
684
688
print (f"Result: { result } " )
685
689
686
690
def save_xml_result (self ):
687
- if not self .ns . xmlpath and not self .testsuite_xml :
691
+ if not self .junit_filename and not self .testsuite_xml :
688
692
return
689
693
690
694
import xml .etree .ElementTree as ET
@@ -703,7 +707,7 @@ def save_xml_result(self):
703
707
for k , v in totals .items ():
704
708
root .set (k , str (v ))
705
709
706
- xmlpath = os .path .join (os_helper .SAVEDCWD , self .ns . xmlpath )
710
+ xmlpath = os .path .join (os_helper .SAVEDCWD , self .junit_filename )
707
711
with open (xmlpath , 'wb' ) as f :
708
712
for s in ET .tostringlist (root ):
709
713
f .write (s )
@@ -785,7 +789,7 @@ def main(self, tests: TestList | None = None):
785
789
ns = self .ns
786
790
self .tests = tests
787
791
788
- if ns . xmlpath :
792
+ if self . junit_filename :
789
793
support .junit_xml_list = self .testsuite_xml = []
790
794
791
795
strip_py_suffix (ns .args )
@@ -844,16 +848,14 @@ def get_exitcode(self):
844
848
return exitcode
845
849
846
850
def action_run_tests (self ):
847
- if self .ns .huntrleaks :
848
- warmup , repetitions , _ = self .ns .huntrleaks
849
- if warmup < 3 :
850
- msg = ("WARNING: Running tests with --huntrleaks/-R and less than "
851
- "3 warmup repetitions can give false positives!" )
852
- print (msg , file = sys .stdout , flush = True )
851
+ if self .hunt_refleak and self .hunt_refleak .warmups < 3 :
852
+ msg = ("WARNING: Running tests with --huntrleaks/-R and "
853
+ "less than 3 warmup repetitions can give false positives!" )
854
+ print (msg , file = sys .stdout , flush = True )
853
855
854
856
# For a partial run, we do not need to clutter the output.
855
857
if (self .want_header
856
- or not (self .pgo or self .ns . quiet or self .ns .single
858
+ or not (self .pgo or self .quiet or self .ns .single
857
859
or self .tests or self .ns .args )):
858
860
self .display_header ()
859
861
@@ -869,7 +871,12 @@ def action_run_tests(self):
869
871
pgo = self .pgo ,
870
872
pgo_extended = self .pgo_extended ,
871
873
output_on_failure = self .output_on_failure ,
872
- timeout = self .timeout )
874
+ timeout = self .timeout ,
875
+ verbose = self .verbose ,
876
+ quiet = self .quiet ,
877
+ hunt_refleak = self .hunt_refleak ,
878
+ test_dir = self .test_dir ,
879
+ junit_filename = self .junit_filename )
873
880
874
881
setup_tests (runtests , self .ns )
875
882
@@ -892,7 +899,7 @@ def _main(self):
892
899
if self .want_wait :
893
900
input ("Press any key to continue..." )
894
901
895
- setup_test_dir (self .ns . testdir )
902
+ setup_test_dir (self .test_dir )
896
903
self .find_tests ()
897
904
898
905
exitcode = 0
0 commit comments