[Zope3-checkins] SVN: zope.testing/branches/benji-parallelize-subprocesses/src/zope/testing/testrunner/ fix bug where default arguments were sometime ignored

Benji York benji at zope.com
Thu Jul 10 22:09:09 EDT 2008


Log message for revision 88223:
  fix bug where default arguments were sometime ignored
  

Changed:
  U   zope.testing/branches/benji-parallelize-subprocesses/src/zope/testing/testrunner/options.py
  U   zope.testing/branches/benji-parallelize-subprocesses/src/zope/testing/testrunner/testrunner-arguments.txt

-=-
Modified: zope.testing/branches/benji-parallelize-subprocesses/src/zope/testing/testrunner/options.py
===================================================================
--- zope.testing/branches/benji-parallelize-subprocesses/src/zope/testing/testrunner/options.py	2008-07-11 02:08:13 UTC (rev 88222)
+++ zope.testing/branches/benji-parallelize-subprocesses/src/zope/testing/testrunner/options.py	2008-07-11 02:09:08 UTC (rev 88223)
@@ -122,7 +122,7 @@
     help="Run tests at all levels.")
 
 searching.add_option(
-    '--list-tests', action="store_true", dest='list_tests', default=False,
+    '--list-tests', action="store_true", dest='list_tests',
     help="List all tests that matched your filters.  Do not run any tests.")
 
 parser.add_option_group(searching)
@@ -192,8 +192,7 @@
 """)
 
 reporting.add_option(
-    '--slow-test', type='float', dest='slow_test_threshold',
-    metavar='N', default=10,
+    '--slow-test', type='float', dest='slow_test_threshold', metavar='N',
     help="""\
 With -c and -vvv, highlight tests that take longer than N seconds (default:
 %default).
@@ -417,7 +416,7 @@
     '-j', action="store", type="int", dest='processes',
     help="""\
 Use up to given number of parallel processes to execute tests.  May decrease
-test run time substantially.  Defaults to %default.
+test run time substantially.  The default is to not run tests in parallel.
 """)
 
 other.add_option(
@@ -448,6 +447,20 @@
 parser.add_option_group(other)
 
 ######################################################################
+# Default values
+
+parser.set_defaults(
+    ignore_dir=['.svn', 'CVS', '{arch}', '.arch-ids', '_darcs'],
+    tests_pattern='^tests$',
+    at_level=1,
+    test_file_pattern='^test',
+    suite_name='test_suite',
+    list_tests=False,
+    slow_test_threshold=10,
+    )
+
+
+######################################################################
 # Command-line processing
 
 def compile_filter(pattern):
@@ -462,19 +475,6 @@
         if (value is not None) and (odict[name] is None):
             odict[name] = value
 
-default_setup_args = [
-    '--tests-pattern', '^tests$',
-    '--at-level', '1',
-    '--ignore', '.svn',
-    '--ignore', 'CVS',
-    '--ignore', '{arch}',
-    '--ignore', '.arch-ids',
-    '--ignore', '_darcs',
-    '--test-file-pattern', '^test',
-    '--suite-name', 'test_suite',
-    ]
-
-
 def get_options(args=None, defaults=None):
     # Because we want to inspect stdout and decide to colorize or not, we
     # replace the --auto-color option with the appropriate --color or
@@ -506,25 +506,18 @@
     apply_auto_progress(args)
     apply_auto_progress(defaults)
 
-    default_setup, _ = parser.parse_args(default_setup_args)
-    assert not _
     if defaults:
         defaults, _ = parser.parse_args(defaults)
         assert not _
-        merge_options(defaults, default_setup)
     else:
-        defaults = default_setup
+        defaults = None
 
     if args is None:
         args = sys.argv
 
-    original_testrunner_args = args
-    args = args[1:]
+    options, positional = parser.parse_args(args[1:], defaults)
+    options.original_testrunner_args = args
 
-    options, positional = parser.parse_args(args)
-    merge_options(options, defaults)
-    options.original_testrunner_args = original_testrunner_args
-
     if options.color:
         options.output = ColorfulOutputFormatter(options)
         options.output.slow_test_threshold = options.slow_test_threshold

Modified: zope.testing/branches/benji-parallelize-subprocesses/src/zope/testing/testrunner/testrunner-arguments.txt
===================================================================
--- zope.testing/branches/benji-parallelize-subprocesses/src/zope/testing/testrunner/testrunner-arguments.txt	2008-07-11 02:08:13 UTC (rev 88222)
+++ zope.testing/branches/benji-parallelize-subprocesses/src/zope/testing/testrunner/testrunner-arguments.txt	2008-07-11 02:09:08 UTC (rev 88223)
@@ -25,3 +25,45 @@
       Tear down samplelayers.Layer11 in N.NNN seconds.
       Tear down samplelayers.Layer1 in N.NNN seconds.
     False
+
+If options already have default values, then passing a different default will
+override.
+
+For example, --list-tests defaults to being turned off, but if we pass in a
+different default, that one takes effect.
+
+    >>> defaults = [
+    ...     '--list-tests',
+    ...     '--path', directory_with_tests,
+    ...     '--tests-pattern', '^sampletestsf?$',
+    ...     ]
+    >>> from zope.testing import testrunner
+    >>> testrunner.run(defaults, 'test --layer 111'.split())
+    Listing samplelayers.Layer111 tests:
+      test_x1 (sample1.sampletests.test111.TestA)
+      test_y0 (sample1.sampletests.test111.TestA)
+      test_z0 (sample1.sampletests.test111.TestA)
+      test_x0 (sample1.sampletests.test111.TestB)
+      test_y1 (sample1.sampletests.test111.TestB)
+      test_z0 (sample1.sampletests.test111.TestB)
+      test_1 (sample1.sampletests.test111.TestNotMuch)
+      test_2 (sample1.sampletests.test111.TestNotMuch)
+      test_3 (sample1.sampletests.test111.TestNotMuch)
+      test_x0 (sample1.sampletests.test111)
+      test_y0 (sample1.sampletests.test111)
+      test_z1 (sample1.sampletests.test111)
+      /home/benji/workspace/zope.testing/1/src/zope/testing/testrunner/testrunner-ex/sample1/sampletests/../../sampletestsl.txt
+      test_x1 (sampletests.test111.TestA)
+      test_y0 (sampletests.test111.TestA)
+      test_z0 (sampletests.test111.TestA)
+      test_x0 (sampletests.test111.TestB)
+      test_y1 (sampletests.test111.TestB)
+      test_z0 (sampletests.test111.TestB)
+      test_1 (sampletests.test111.TestNotMuch)
+      test_2 (sampletests.test111.TestNotMuch)
+      test_3 (sampletests.test111.TestNotMuch)
+      test_x0 (sampletests.test111)
+      test_y0 (sampletests.test111)
+      test_z1 (sampletests.test111)
+      /home/benji/workspace/zope.testing/1/src/zope/testing/testrunner/testrunner-ex/sampletests/../sampletestsl.txt
+    False



More information about the Zope3-Checkins mailing list