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 , MatchTestsDict , RunTests , TestResult )
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 ,
35
35
EXITCODE_INTERRUPTED = 130
36
36
37
37
38
+ TestsList = list [str ]
39
+
40
+
38
41
class Regrtest :
39
42
"""Execute a test suite.
40
43
@@ -58,24 +61,24 @@ class Regrtest:
58
61
directly to set the values that would normally be set by flags
59
62
on the command line.
60
63
"""
61
- def __init__ (self ):
64
+ def __init__ (self , ns : Namespace ):
62
65
# Namespace of command line options
63
- self .ns = None
66
+ self .ns : Namespace = ns
64
67
65
68
# tests
66
69
self .tests = []
67
70
self .selected = []
68
71
self .all_runtests : list [RunTests ] = []
69
72
70
73
# 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 ] = []
74
+ self .good : TestsList = []
75
+ self .bad : TestsList = []
76
+ self .rerun_bad : TestsList = []
77
+ self .skipped : TestsList = []
78
+ self .resource_denied : TestsList = []
79
+ self .environment_changed : TestsList = []
80
+ self .run_no_tests : TestsList = []
81
+ self .rerun : TestsList = []
79
82
80
83
self .need_rerun : list [TestResult ] = []
81
84
self .first_state : str | None = None
@@ -184,29 +187,7 @@ def display_progress(self, test_index, text):
184
187
line = f"{ line } /{ fails } "
185
188
self .log (f"[{ line } ] { text } " )
186
189
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 ):
190
+ def find_tests (self ):
210
191
ns = self .ns
211
192
single = ns .single
212
193
fromfile = ns .fromfile
@@ -216,8 +197,6 @@ def find_tests(self, tests):
216
197
starting_test = ns .start
217
198
randomize = ns .randomize
218
199
219
- self .tests = tests
220
-
221
200
if single :
222
201
self .next_single_filename = os .path .join (self .tmp_dir , 'pynexttest' )
223
202
try :
@@ -737,8 +716,12 @@ def fix_umask(self):
737
716
os .umask (old_mask )
738
717
739
718
def set_temp_dir (self ):
740
- if self .ns .tempdir :
741
- self .tmp_dir = self .ns .tempdir
719
+ ns = self .ns
720
+ if ns .tempdir :
721
+ ns .tempdir = os .path .expanduser (ns .tempdir )
722
+
723
+ if ns .tempdir :
724
+ self .tmp_dir = ns .tempdir
742
725
743
726
if not self .tmp_dir :
744
727
# When tests are run from the Python build directory, it is best practice
@@ -795,14 +778,20 @@ def cleanup(self):
795
778
print ("Remove file: %s" % name )
796
779
os_helper .unlink (name )
797
780
798
- def main (self , tests = None , ** kwargs ):
799
- self .parse_args (kwargs )
781
+ def main (self , tests : TestsList | None = None ):
782
+ ns = self .ns
783
+ self .tests = tests
784
+
785
+ if ns .xmlpath :
786
+ support .junit_xml_list = self .testsuite_xml = []
787
+
788
+ strip_py_suffix (ns .args )
800
789
801
790
self .set_temp_dir ()
802
791
803
792
self .fix_umask ()
804
793
805
- if self . ns .cleanup :
794
+ if ns .cleanup :
806
795
self .cleanup ()
807
796
sys .exit (0 )
808
797
@@ -817,9 +806,9 @@ def main(self, tests=None, **kwargs):
817
806
# When using multiprocessing, worker processes will use test_cwd
818
807
# as their parent temporary directory. So when the main process
819
808
# exit, it removes also subdirectories of worker processes.
820
- self . ns .tempdir = test_cwd
809
+ ns .tempdir = test_cwd
821
810
822
- self ._main (tests , kwargs )
811
+ self ._main ()
823
812
except SystemExit as exc :
824
813
# bpo-38203: Python can hang at exit in Py_Finalize(), especially
825
814
# on threading._shutdown() call: put a timeout
@@ -862,7 +851,7 @@ def action_run_tests(self):
862
851
self .display_summary ()
863
852
self .finalize ()
864
853
865
- def _main (self , tests , kwargs ):
854
+ def _main (self ):
866
855
if self .is_worker ():
867
856
from test .libregrtest .runtest_mp import run_tests_worker
868
857
run_tests_worker (self .ns .worker_args )
@@ -872,7 +861,7 @@ def _main(self, tests, kwargs):
872
861
input ("Press any key to continue..." )
873
862
874
863
setup_tests (self .ns )
875
- self .find_tests (tests )
864
+ self .find_tests ()
876
865
877
866
exitcode = 0
878
867
if self .ns .list_tests :
@@ -888,4 +877,5 @@ def _main(self, tests, kwargs):
888
877
889
878
def main (tests = None , ** kwargs ):
890
879
"""Run the Python suite."""
891
- Regrtest ().main (tests = tests , ** kwargs )
880
+ ns = _parse_args (sys .argv [1 :], ** kwargs )
881
+ Regrtest (ns ).main (tests = tests )
0 commit comments