1- import locale
21import os
3- import platform
42import random
53import re
64import sys
75import time
8- import unittest
96
107from test import support
118from test .support import os_helper
129
1310from .cmdline import _parse_args , Namespace
14- from .findtests import findtests , split_test_packages
11+ from .findtests import findtests , split_test_packages , list_cases
1512from .logger import Logger
1613from .result import State
1714from .runtests import RunTests , HuntRefleak
2219from .utils import (
2320 StrPath , StrJSON , TestName , TestList , TestTuple , FilterTuple ,
2421 strip_py_suffix , count , format_duration ,
25- printlist , get_build_info , get_temp_dir , get_work_dir , exit_timeout ,
26- abs_module_name )
22+ printlist , get_temp_dir , get_work_dir , exit_timeout ,
23+ display_header , cleanup_temp_dir )
2724
2825
2926class Regrtest :
@@ -214,36 +211,6 @@ def list_tests(tests: TestTuple):
214211 for name in tests :
215212 print (name )
216213
217- def _list_cases (self , suite ):
218- for test in suite :
219- if isinstance (test , unittest .loader ._FailedTest ):
220- continue
221- if isinstance (test , unittest .TestSuite ):
222- self ._list_cases (test )
223- elif isinstance (test , unittest .TestCase ):
224- if support .match_test (test ):
225- print (test .id ())
226-
227- def list_cases (self , tests : TestTuple ):
228- support .verbose = False
229- support .set_match_tests (self .match_tests , self .ignore_tests )
230-
231- skipped = []
232- for test_name in tests :
233- module_name = abs_module_name (test_name , self .test_dir )
234- try :
235- suite = unittest .defaultTestLoader .loadTestsFromName (module_name )
236- self ._list_cases (suite )
237- except unittest .SkipTest :
238- skipped .append (test_name )
239-
240- if skipped :
241- sys .stdout .flush ()
242- stderr = sys .stderr
243- print (file = stderr )
244- print (count (len (skipped ), "test" ), "skipped:" , file = stderr )
245- printlist (skipped , file = stderr )
246-
247214 def _rerun_failed_tests (self , runtests : RunTests ):
248215 # Configure the runner to re-run tests
249216 if self .num_workers == 0 :
@@ -363,45 +330,6 @@ def run_tests_sequentially(self, runtests):
363330
364331 return tracer
365332
366- @staticmethod
367- def display_header ():
368- # Print basic platform information
369- print ("==" , platform .python_implementation (), * sys .version .split ())
370- print ("==" , platform .platform (aliased = True ),
371- "%s-endian" % sys .byteorder )
372- print ("== Python build:" , ' ' .join (get_build_info ()))
373- print ("== cwd:" , os .getcwd ())
374- cpu_count = os .cpu_count ()
375- if cpu_count :
376- print ("== CPU count:" , cpu_count )
377- print ("== encodings: locale=%s, FS=%s"
378- % (locale .getencoding (), sys .getfilesystemencoding ()))
379-
380- # This makes it easier to remember what to set in your local
381- # environment when trying to reproduce a sanitizer failure.
382- asan = support .check_sanitizer (address = True )
383- msan = support .check_sanitizer (memory = True )
384- ubsan = support .check_sanitizer (ub = True )
385- sanitizers = []
386- if asan :
387- sanitizers .append ("address" )
388- if msan :
389- sanitizers .append ("memory" )
390- if ubsan :
391- sanitizers .append ("undefined behavior" )
392- if not sanitizers :
393- return
394-
395- print (f"== sanitizers: { ', ' .join (sanitizers )} " )
396- for sanitizer , env_var in (
397- (asan , "ASAN_OPTIONS" ),
398- (msan , "MSAN_OPTIONS" ),
399- (ubsan , "UBSAN_OPTIONS" ),
400- ):
401- options = os .environ .get (env_var )
402- if sanitizer and options is not None :
403- print (f"== { env_var } ={ options !r} " )
404-
405333 def get_state (self ):
406334 state = self .results .get_state (self .fail_env_changed )
407335 if self .first_state :
@@ -445,20 +373,6 @@ def display_summary(self):
445373 state = self .get_state ()
446374 print (f"Result: { state } " )
447375
448- @staticmethod
449- def cleanup_temp_dir (tmp_dir : StrPath ):
450- import glob
451-
452- path = os .path .join (glob .escape (tmp_dir ), 'test_python_*' )
453- print ("Cleanup %s directory" % tmp_dir )
454- for name in glob .glob (path ):
455- if os .path .isdir (name ):
456- print ("Remove directory: %s" % name )
457- os_helper .rmtree (name )
458- else :
459- print ("Remove file: %s" % name )
460- os_helper .unlink (name )
461-
462376 def create_run_tests (self , tests : TestTuple ):
463377 return RunTests (
464378 tests ,
@@ -496,7 +410,7 @@ def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
496410 if (self .want_header
497411 or not (self .pgo or self .quiet or self .single_test_run
498412 or tests or self .cmdline_args )):
499- self . display_header ()
413+ display_header ()
500414
501415 if self .randomize :
502416 print ("Using random seed" , self .random_seed )
@@ -554,7 +468,7 @@ def main(self, tests: TestList | None = None):
554468 self .tmp_dir = get_temp_dir (self .tmp_dir )
555469
556470 if self .want_cleanup :
557- self . cleanup_temp_dir (self .tmp_dir )
471+ cleanup_temp_dir (self .tmp_dir )
558472 sys .exit (0 )
559473
560474 if self .want_wait :
@@ -567,7 +481,10 @@ def main(self, tests: TestList | None = None):
567481 if self .want_list_tests :
568482 self .list_tests (selected )
569483 elif self .want_list_cases :
570- self .list_cases (selected )
484+ list_cases (selected ,
485+ match_tests = self .match_tests ,
486+ ignore_tests = self .ignore_tests ,
487+ test_dir = self .test_dir )
571488 else :
572489 exitcode = self .run_tests (selected , tests )
573490
0 commit comments