[Zope3-checkins] SVN: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/ Factored out doctest flag setup into its own feature.

Christian Theune ct at gocept.com
Sun May 4 07:51:13 EDT 2008


Log message for revision 86339:
  Factored out doctest flag setup into its own feature.
  

Changed:
  A   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/doctest.py
  U   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py

-=-
Added: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/doctest.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/doctest.py	                        (rev 0)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/doctest.py	2008-05-04 11:51:12 UTC (rev 86339)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2004-2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Doc test support for the test runner.
+
+$Id: __init__.py 86232 2008-05-03 15:09:33Z ctheune $
+"""
+
+from zope.testing import doctest
+import zope.testing.testrunner.feature
+
+
+class DocTest(zope.testing.testrunner.feature.Feature):
+
+    active = True
+
+    def global_setup(self):
+        options = self.runner.options
+
+        self.old_reporting_flags = doctest.set_unittest_reportflags(0)
+
+        reporting_flags = 0
+        if options.ndiff:
+            reporting_flags = doctest.REPORT_NDIFF
+        if options.udiff:
+            if reporting_flags:
+                output.error("Can only give one of --ndiff, --udiff, or --cdiff")
+                sys.exit(1)
+            reporting_flags = doctest.REPORT_UDIFF
+        if options.cdiff:
+            if reporting_flags:
+                output.error("Can only give one of --ndiff, --udiff, or --cdiff")
+                sys.exit(1)
+            reporting_flags = doctest.REPORT_CDIFF
+        if options.report_only_first_failure:
+            reporting_flags |= doctest.REPORT_ONLY_FIRST_FAILURE
+
+        if reporting_flags:
+            doctest.set_unittest_reportflags(reporting_flags)
+
+    def global_shutdown(self):
+        doctest.set_unittest_reportflags(self.old_reporting_flags)


Property changes on: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/doctest.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py	2008-05-04 11:04:44 UTC (rev 86338)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py	2008-05-04 11:51:12 UTC (rev 86339)
@@ -35,12 +35,15 @@
 from zope.testing.testrunner.find import find_tests, test_dirs
 from zope.testing.testrunner.find import StartUpFailure, import_name
 from zope.testing.testrunner.find import name_from_layer, _layer_name_cache
-from zope.testing.testrunner import coverage
 from zope.testing.testrunner.refcount import TrackRefs
 from zope.testing.testrunner.options import get_options
+import zope.testing.testrunner.coverage
+import zope.testing.testrunner.doctest
 
+
 real_pdb_set_trace = pdb.set_trace
 
+
 PYREFCOUNT_PATTERN = re.compile('\[[0-9]+ refs\]')
 
 
@@ -167,7 +170,8 @@
         # XXX I moved this here mechanically.
         self.test_directories = test_dirs(self.options, {})
 
-        self.features.append(coverage.Coverage(self))
+        self.features.append(zope.testing.testrunner.coverage.Coverage(self))
+        self.features.append(zope.testing.testrunner.doctest.DocTest(self))
 
         # Remove all features that aren't activated
         self.features = [f for f in self.features if f.active]
@@ -182,9 +186,6 @@
         # It's not at all clear that the test runner should be doing this.
         configure_logging()
 
-        # Control reporting flags during run
-        self.old_reporting_flags = doctest.set_unittest_reportflags(0)
-
         # Setup profiling
         if (self.options.profile
             and sys.version_info[:3] <= (2,4,1)
@@ -235,29 +236,7 @@
                 new_flags |= getattr(gc, op)
             gc.set_debug(new_flags)
 
-        # Set up doctest support
-        self.old_reporting_flags = doctest.set_unittest_reportflags(0)
-        reporting_flags = 0
-        if self.options.ndiff:
-            reporting_flags = doctest.REPORT_NDIFF
-        if self.options.udiff:
-            if reporting_flags:
-                output.error("Can only give one of --ndiff, --udiff, or --cdiff")
-                sys.exit(1)
-            reporting_flags = doctest.REPORT_UDIFF
-        if self.options.cdiff:
-            if reporting_flags:
-                output.error("Can only give one of --ndiff, --udiff, or --cdiff")
-                sys.exit(1)
-            reporting_flags = doctest.REPORT_CDIFF
-        if self.options.report_only_first_failure:
-            reporting_flags |= doctest.REPORT_ONLY_FIRST_FAILURE
 
-        if reporting_flags:
-            doctest.set_unittest_reportflags(reporting_flags)
-        else:
-            doctest.set_unittest_reportflags(self.old_reporting_flags)
-
         # Set up time measurement
         def start_time_recording():
             self.start_time = time.time()
@@ -373,8 +352,6 @@
         self.failed = bool(self.import_errors or self.failures or self.errors)
 
     def shutdown_features(self):
-        doctest.set_unittest_reportflags(self.old_reporting_flags)
-
         if self.options.gc_option:
             gc.set_debug(self.old_flags)
 
@@ -391,8 +368,6 @@
                 self.profiler_stats = self.profiler.loadStats(self.prof_glob)
                 self.profiler_stats.sort_stats('cumulative', 'calls')
 
-        doctest.set_unittest_reportflags(self.old_reporting_flags)
-
     def report(self):
         if self.options.resume_layer:
             sys.stdout.close()



More information about the Zope3-Checkins mailing list