10
10
import tempfile
11
11
import textwrap
12
12
import time
13
+ import unittest
13
14
from test .libregrtest .cmdline import _parse_args
14
15
from test .libregrtest .runtest import (
15
- findtests , runtest ,
16
+ findtests , runtest , get_abs_module ,
16
17
STDTESTS , NOTTESTS , PASSED , FAILED , ENV_CHANGED , SKIPPED , RESOURCE_DENIED ,
17
18
INTERRUPTED , CHILD_ERROR ,
18
19
PROGRESS_MIN_TIME , format_test_result )
@@ -248,6 +249,29 @@ def list_tests(self):
248
249
for name in self .selected :
249
250
print (name )
250
251
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
+
251
275
def rerun_failed_tests (self ):
252
276
self .ns .verbose = True
253
277
self .ns .failfast = False
@@ -499,6 +523,10 @@ def _main(self, tests, kwargs):
499
523
self .list_tests ()
500
524
sys .exit (0 )
501
525
526
+ if self .ns .list_cases :
527
+ self .list_cases ()
528
+ sys .exit (0 )
529
+
502
530
self .run_tests ()
503
531
self .display_result ()
504
532
@@ -525,7 +553,7 @@ def count(n, word):
525
553
return "%d %ss" % (n , word )
526
554
527
555
528
- def printlist (x , width = 70 , indent = 4 ):
556
+ def printlist (x , width = 70 , indent = 4 , file = None ):
529
557
"""Print the elements of iterable x to stdout.
530
558
531
559
Optional arg width (default 70) is the maximum line length.
@@ -536,7 +564,8 @@ def printlist(x, width=70, indent=4):
536
564
blanks = ' ' * indent
537
565
# Print the sorted list: 'x' may be a '--random' list or a set()
538
566
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 )
540
569
541
570
542
571
def main (tests = None , ** kwargs ):
0 commit comments