[Zope3-checkins] SVN: zope.testing/branches/list-tests/src/zope/testing/testrunner Add a --list-tests option. It is useful when you want to trim down the set of

Marius Gedminas marius at pov.lt
Sun Jan 14 14:52:18 EST 2007


Log message for revision 72034:
  Add a --list-tests option.  It is useful when you want to trim down the set of
  tests, and want to be sure those and only those tests you want will be run.
  (You could do the same with test.py -vv, but several iterations of that with
  different combination sof -t/-m/-s/--layer/--level options might take ages.)
  
  

Changed:
  U   zope.testing/branches/list-tests/src/zope/testing/testrunner-test-selection.txt
  U   zope.testing/branches/list-tests/src/zope/testing/testrunner.py

-=-
Modified: zope.testing/branches/list-tests/src/zope/testing/testrunner-test-selection.txt
===================================================================
--- zope.testing/branches/list-tests/src/zope/testing/testrunner-test-selection.txt	2007-01-14 19:31:32 UTC (rev 72033)
+++ zope.testing/branches/list-tests/src/zope/testing/testrunner-test-selection.txt	2007-01-14 19:52:17 UTC (rev 72034)
@@ -519,3 +519,46 @@
         test_y0 (sampletests.test_one)
       Ran 39 tests with 0 failures and 0 errors in 0.009 seconds.
     False
+
+
+Listing Selected Tests
+----------------------
+
+When you're trying to figure out why the test you want is not matched by the
+pattern you specified, it is convenient to see which tests match your
+specifications.
+
+    >>> sys.argv = 'test --all -m sample1 -t test_y0 --list-tests'.split()
+    >>> testrunner.run(defaults)
+    Listing unit tests:
+      test_y0 (sample1.sampletestsf.TestA)
+      test_y0 (sample1.sampletestsf)
+      test_y0 (sample1.sample11.sampletests.TestA)
+      test_y0 (sample1.sample11.sampletests.TestA3)
+      test_y0 (sample1.sample11.sampletests)
+      test_y0 (sample1.sample13.sampletests.TestA)
+      test_y0 (sample1.sample13.sampletests)
+      test_y0 (sample1.sampletests.test1.TestA)
+      test_y0 (sample1.sampletests.test1)
+      test_y0 (sample1.sampletests.test_one.TestA)
+      test_y0 (sample1.sampletests.test_one)
+    Listing samplelayers.Layer11 tests:
+      test_y0 (sample1.sampletests.test11.TestA)
+      test_y0 (sample1.sampletests.test11)
+    Listing samplelayers.Layer111 tests:
+      test_y0 (sample1.sampletests.test111.TestA)
+      test_y0 (sample1.sampletests.test111)
+    Listing samplelayers.Layer112 tests:
+      test_y0 (sample1.sampletests.test112.TestA)
+      test_y0 (sample1.sampletests.test112)
+    Listing samplelayers.Layer12 tests:
+      test_y0 (sample1.sampletests.test12.TestA)
+      test_y0 (sample1.sampletests.test12)
+    Listing samplelayers.Layer121 tests:
+      test_y0 (sample1.sampletests.test121.TestA)
+      test_y0 (sample1.sampletests.test121)
+    Listing samplelayers.Layer122 tests:
+      test_y0 (sample1.sampletests.test122.TestA)
+      test_y0 (sample1.sampletests.test122)
+    False
+

Modified: zope.testing/branches/list-tests/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/branches/list-tests/src/zope/testing/testrunner.py	2007-01-14 19:31:32 UTC (rev 72033)
+++ zope.testing/branches/list-tests/src/zope/testing/testrunner.py	2007-01-14 19:52:17 UTC (rev 72034)
@@ -391,7 +391,6 @@
             print_traceback("Module: %s\n" % error.module, error.exc_info),
         print
 
-
     if 'unit' in tests_by_layer_name:
         tests = tests_by_layer_name.pop('unit')
         if (not options.non_unit) and not options.resume_layer:
@@ -405,9 +404,12 @@
                 should_run = True
 
             if should_run:
-                print "Running unit tests:"
-                nlayers += 1
-                ran += run_tests(options, tests, 'unit', failures, errors)
+                if options.list_tests:
+                    list_tests(options, tests, 'unit')
+                else:
+                    print "Running unit tests:"
+                    nlayers += 1
+                    ran += run_tests(options, tests, 'unit', failures, errors)
 
     setup_layers = {}
 
@@ -426,6 +428,11 @@
         ]
 
 
+    if options.list_tests:
+        for layer_name, layer, tests in layers_to_run:
+            list_tests(options, tests, layer_name)
+        return True
+
     for layer_name, layer, tests in layers_to_run:
         nlayers += 1
         try:
@@ -485,6 +492,11 @@
 
     return not bool(import_errors or failures or errors)
 
+def list_tests(options, tests, layer_name):
+    print "Listing %s tests:" % layer_name
+    for test in tests:
+        print ' ', test
+
 def run_tests(options, tests, name, failures, errors):
     repeat = options.repeat or 1
     repeat_range = iter(range(repeat))
@@ -1478,6 +1490,10 @@
     '--all', action="store_true", dest='all',
     help="Run tests at all levels.")
 
+searching.add_option(
+    '--list-tests', action="store_true", dest='list_tests', default=False,
+    help="List all tests that matched your filters.  Do not run any tests.")
+
 parser.add_option_group(searching)
 
 ######################################################################



More information about the Zope3-Checkins mailing list