1010import tempfile
1111import textwrap
1212import time
13+ import unittest
1314from test .libregrtest .cmdline import _parse_args
1415from test .libregrtest .runtest import (
15- findtests , runtest ,
16+ findtests , runtest , get_abs_module ,
1617 STDTESTS , NOTTESTS , PASSED , FAILED , ENV_CHANGED , SKIPPED , RESOURCE_DENIED ,
1718 INTERRUPTED , CHILD_ERROR ,
1819 PROGRESS_MIN_TIME , format_test_result )
@@ -248,6 +249,29 @@ def list_tests(self):
248249 for name in self .selected :
249250 print (name )
250251
252+ def _list_cases (self , suite ):
253+ for test in suite :
254+ if isinstance (test , unittest .loader ._FailedTest ):
255+ continue
256+ if isinstance (test , unittest .TestSuite ):
257+ self ._list_cases (test )
258+ elif isinstance (test , unittest .TestCase ):
259+ print (test .id ())
260+
261+ def list_cases (self ):
262+ for test in self .selected :
263+ abstest = get_abs_module (self .ns , test )
264+ try :
265+ suite = unittest .defaultTestLoader .loadTestsFromName (abstest )
266+ self ._list_cases (suite )
267+ except unittest .SkipTest :
268+ self .skipped .append (test )
269+
270+ if self .skipped :
271+ print (file = sys .stderr )
272+ print (count (len (self .skipped ), "test" ), "skipped:" , file = sys .stderr )
273+ printlist (self .skipped , file = sys .stderr )
274+
251275 def rerun_failed_tests (self ):
252276 self .ns .verbose = True
253277 self .ns .failfast = False
@@ -499,6 +523,10 @@ def _main(self, tests, kwargs):
499523 self .list_tests ()
500524 sys .exit (0 )
501525
526+ if self .ns .list_cases :
527+ self .list_cases ()
528+ sys .exit (0 )
529+
502530 self .run_tests ()
503531 self .display_result ()
504532
@@ -525,7 +553,7 @@ def count(n, word):
525553 return "%d %ss" % (n , word )
526554
527555
528- def printlist (x , width = 70 , indent = 4 ):
556+ def printlist (x , width = 70 , indent = 4 , file = None ):
529557 """Print the elements of iterable x to stdout.
530558
531559 Optional arg width (default 70) is the maximum line length.
@@ -536,7 +564,8 @@ def printlist(x, width=70, indent=4):
536564 blanks = ' ' * indent
537565 # Print the sorted list: 'x' may be a '--random' list or a set()
538566 print (textwrap .fill (' ' .join (str (elt ) for elt in sorted (x )), width ,
539- initial_indent = blanks , subsequent_indent = blanks ))
567+ initial_indent = blanks , subsequent_indent = blanks ),
568+ file = file )
540569
541570
542571def main (tests = None , ** kwargs ):
0 commit comments