9
9
import tempfile
10
10
import time
11
11
import unittest
12
- from test .libregrtest .cmdline import _parse_args
12
+ from test .libregrtest .cmdline import _parse_args , Namespace
13
13
from test .libregrtest .runtest import (
14
14
findtests , split_test_packages , runtest , abs_module_name ,
15
- PROGRESS_MIN_TIME , State , MatchTestsDict , RunTests )
15
+ PROGRESS_MIN_TIME , State , FilterDict , RunTests , TestResult , TestList )
16
16
from test .libregrtest .setup import setup_tests
17
17
from test .libregrtest .pgo import setup_pgo_tests
18
18
from test .libregrtest .utils import (strip_py_suffix , count , format_duration ,
@@ -58,24 +58,24 @@ class Regrtest:
58
58
directly to set the values that would normally be set by flags
59
59
on the command line.
60
60
"""
61
- def __init__ (self ):
61
+ def __init__ (self , ns : Namespace ):
62
62
# Namespace of command line options
63
- self .ns = None
63
+ self .ns : Namespace = ns
64
64
65
65
# tests
66
66
self .tests = []
67
67
self .selected = []
68
68
self .all_runtests : list [RunTests ] = []
69
69
70
70
# test results
71
- self .good : list [ str ] = []
72
- self .bad : list [ str ] = []
73
- self .rerun_bad : list [ str ] = []
74
- self .skipped : list [ str ] = []
75
- self .resource_denied : list [ str ] = []
76
- self .environment_changed : list [ str ] = []
77
- self .run_no_tests : list [ str ] = []
78
- self .rerun : list [ str ] = []
71
+ self .good : TestList = []
72
+ self .bad : TestList = []
73
+ self .rerun_bad : TestList = []
74
+ self .skipped : TestList = []
75
+ self .resource_denied : TestList = []
76
+ self .environment_changed : TestList = []
77
+ self .run_no_tests : TestList = []
78
+ self .rerun : TestList = []
79
79
80
80
self .need_rerun : list [TestResult ] = []
81
81
self .first_state : str | None = None
@@ -184,29 +184,7 @@ def display_progress(self, test_index, text):
184
184
line = f"{ line } /{ fails } "
185
185
self .log (f"[{ line } ] { text } " )
186
186
187
- def parse_args (self , kwargs ):
188
- ns = _parse_args (sys .argv [1 :], ** kwargs )
189
-
190
- if ns .xmlpath :
191
- support .junit_xml_list = self .testsuite_xml = []
192
-
193
- strip_py_suffix (ns .args )
194
-
195
- if ns .huntrleaks :
196
- warmup , repetitions , _ = ns .huntrleaks
197
- if warmup < 1 or repetitions < 1 :
198
- msg = ("Invalid values for the --huntrleaks/-R parameters. The "
199
- "number of warmups and repetitions must be at least 1 "
200
- "each (1:1)." )
201
- print (msg , file = sys .stderr , flush = True )
202
- sys .exit (2 )
203
-
204
- if ns .tempdir :
205
- ns .tempdir = os .path .expanduser (ns .tempdir )
206
-
207
- self .ns = ns
208
-
209
- def find_tests (self , tests ):
187
+ def find_tests (self ):
210
188
ns = self .ns
211
189
single = ns .single
212
190
fromfile = ns .fromfile
@@ -216,8 +194,6 @@ def find_tests(self, tests):
216
194
starting_test = ns .start
217
195
randomize = ns .randomize
218
196
219
- self .tests = tests
220
-
221
197
if single :
222
198
self .next_single_filename = os .path .join (self .tmp_dir , 'pynexttest' )
223
199
try :
@@ -321,7 +297,7 @@ def list_cases(self):
321
297
print (count (len (skipped ), "test" ), "skipped:" , file = stderr )
322
298
printlist (skipped , file = stderr )
323
299
324
- def get_rerun_match (self , rerun_list ) -> MatchTestsDict :
300
+ def get_rerun_match (self , rerun_list ) -> FilterDict :
325
301
rerun_match_tests = {}
326
302
for result in rerun_list :
327
303
match_tests = result .get_rerun_match_tests ()
@@ -352,7 +328,7 @@ def _rerun_failed_tests(self, need_rerun):
352
328
353
329
# Re-run failed tests
354
330
self .log (f"Re-running { len (tests )} failed tests in verbose mode in subprocesses" )
355
- runtests = RunTests (tests , match_tests = match_tests , rerun = True )
331
+ runtests = RunTests (tuple ( tests ) , match_tests = match_tests , rerun = True )
356
332
self .all_runtests .append (runtests )
357
333
self ._run_tests_mp (runtests )
358
334
@@ -624,7 +600,7 @@ def run_tests(self):
624
600
625
601
tests = self .selected
626
602
self .set_tests (tests )
627
- runtests = RunTests (tests , forever = self .ns .forever )
603
+ runtests = RunTests (tuple ( tests ) , forever = self .ns .forever )
628
604
self .all_runtests .append (runtests )
629
605
if self .ns .use_mp :
630
606
self ._run_tests_mp (runtests )
@@ -737,8 +713,12 @@ def fix_umask(self):
737
713
os .umask (old_mask )
738
714
739
715
def set_temp_dir (self ):
740
- if self .ns .tempdir :
741
- self .tmp_dir = self .ns .tempdir
716
+ ns = self .ns
717
+ if ns .tempdir :
718
+ ns .tempdir = os .path .expanduser (ns .tempdir )
719
+
720
+ if ns .tempdir :
721
+ self .tmp_dir = ns .tempdir
742
722
743
723
if not self .tmp_dir :
744
724
# When tests are run from the Python build directory, it is best practice
@@ -795,14 +775,20 @@ def cleanup(self):
795
775
print ("Remove file: %s" % name )
796
776
os_helper .unlink (name )
797
777
798
- def main (self , tests = None , ** kwargs ):
799
- self .parse_args (kwargs )
778
+ def main (self , tests : TestList | None = None ):
779
+ ns = self .ns
780
+ self .tests = tests
781
+
782
+ if ns .xmlpath :
783
+ support .junit_xml_list = self .testsuite_xml = []
784
+
785
+ strip_py_suffix (ns .args )
800
786
801
787
self .set_temp_dir ()
802
788
803
789
self .fix_umask ()
804
790
805
- if self . ns .cleanup :
791
+ if ns .cleanup :
806
792
self .cleanup ()
807
793
sys .exit (0 )
808
794
@@ -817,9 +803,9 @@ def main(self, tests=None, **kwargs):
817
803
# When using multiprocessing, worker processes will use test_cwd
818
804
# as their parent temporary directory. So when the main process
819
805
# exit, it removes also subdirectories of worker processes.
820
- self . ns .tempdir = test_cwd
806
+ ns .tempdir = test_cwd
821
807
822
- self ._main (tests , kwargs )
808
+ self ._main ()
823
809
except SystemExit as exc :
824
810
# bpo-38203: Python can hang at exit in Py_Finalize(), especially
825
811
# on threading._shutdown() call: put a timeout
@@ -862,7 +848,7 @@ def action_run_tests(self):
862
848
self .display_summary ()
863
849
self .finalize ()
864
850
865
- def _main (self , tests , kwargs ):
851
+ def _main (self ):
866
852
if self .is_worker ():
867
853
from test .libregrtest .runtest_mp import run_tests_worker
868
854
run_tests_worker (self .ns .worker_args )
@@ -872,7 +858,7 @@ def _main(self, tests, kwargs):
872
858
input ("Press any key to continue..." )
873
859
874
860
setup_tests (self .ns )
875
- self .find_tests (tests )
861
+ self .find_tests ()
876
862
877
863
exitcode = 0
878
864
if self .ns .list_tests :
@@ -888,4 +874,5 @@ def _main(self, tests, kwargs):
888
874
889
875
def main (tests = None , ** kwargs ):
890
876
"""Run the Python suite."""
891
- Regrtest ().main (tests = tests , ** kwargs )
877
+ ns = _parse_args (sys .argv [1 :], ** kwargs )
878
+ Regrtest (ns ).main (tests = tests )
0 commit comments