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

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


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

Changed:
  U   zope.testing/trunk/src/zope/testing/testrunner/options.py
  U   zope.testing/trunk/src/zope/testing/testrunner/testrunner-arguments.txt

-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner/options.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/options.py	2008-07-11 02:09:08 UTC (rev 88223)
+++ zope.testing/trunk/src/zope/testing/testrunner/options.py	2008-07-11 02:14:34 UTC (rev 88224)
@@ -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).
@@ -407,6 +406,13 @@
 other = optparse.OptionGroup(parser, "Other", "Other options")
 
 other.add_option(
+    '--exit-with-status', action="store_true", dest='exitwithstatus',
+    help="""\
+Return an error exit status if the tests failed.  This can be useful for
+an invoking process that wants to monitor the result of a test run.
+""")
+
+other.add_option(
     '--keepbytecode', '-k', action="store_true", dest='keepbytecode',
     help="""\
 Normally, the test runner scans the test paths and the test
@@ -431,16 +437,23 @@
 compilation to .pyc/.pyo.  Use of this option implies --keepbytecode.
 """)
 
-other.add_option(
-    '--exit-with-status', action="store_true", dest='exitwithstatus',
-    help="""\
-Return an error exit status if the tests failed.  This can be useful for
-an invoking process that wants to monitor the result of a test run.
-""")
-
 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):
@@ -455,19 +468,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
@@ -499,25 +499,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/trunk/src/zope/testing/testrunner/testrunner-arguments.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-arguments.txt	2008-07-11 02:09:08 UTC (rev 88223)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-arguments.txt	2008-07-11 02:14:34 UTC (rev 88224)
@@ -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