[Checkins] SVN: z3c.testsetup/branches/new_markers/src/z3c/testsetup/doctesting.py Setup doctests with custom setup/teardown methods if requested.

Uli Fouquet uli at gnufix.de
Wed Sep 3 09:50:40 EDT 2008


Log message for revision 90761:
  Setup doctests with custom setup/teardown methods if requested.

Changed:
  U   z3c.testsetup/branches/new_markers/src/z3c/testsetup/doctesting.py

-=-
Modified: z3c.testsetup/branches/new_markers/src/z3c/testsetup/doctesting.py
===================================================================
--- z3c.testsetup/branches/new_markers/src/z3c/testsetup/doctesting.py	2008-09-03 13:49:45 UTC (rev 90760)
+++ z3c.testsetup/branches/new_markers/src/z3c/testsetup/doctesting.py	2008-09-03 13:50:40 UTC (rev 90761)
@@ -18,7 +18,8 @@
 from os import listdir
 from zope.testing import doctest, cleanup
 from z3c.testsetup.base import BasicTestSetup
-from z3c.testsetup.util import get_package, get_marker_from_file, warn
+from z3c.testsetup.util import (get_package, get_marker_from_file, warn,
+                                get_attribute)
 
 class DocTestSetup(BasicTestSetup):
     """A test setup for doctests."""
@@ -51,13 +52,24 @@
         suite = unittest.TestSuite()
         for name in docfiles:
             layerdef = get_marker_from_file('layer', name)
+
             zcml_layer = self.getZCMLLayer(name, 'zcml-layer')
             if zcml_layer is not None:
                 layerdef = zcml_layer
+
             functional_zcml_layer = self.getZCMLLayer(
                 name, 'functional-zcml-layer')
             if functional_zcml_layer is not None:
                 layerdef = functional_zcml_layer
+
+            setup = get_marker_from_file('setup', name) or self.setUp
+            if setup is not None and isinstance(setup, basestring):
+                setup = get_attribute(setup)
+
+            teardown = get_marker_from_file('teardown', name) or self.tearDown
+            if teardown is not None and isinstance(teardown, basestring):
+                teardown = get_attribute(teardown)
+
             if os.path.isabs(name):
                 # We get absolute pathnames, but we need relative ones...
                 common_prefix = os.path.commonprefix([self.package.__file__,
@@ -70,8 +82,8 @@
             test = suite_creator(
                 name,
                 package=self.package,
-                setUp=self.setUp,
-                tearDown=self.tearDown,
+                setUp=setup,
+                tearDown=teardown,
                 globs=self.globs,
                 optionflags=self.optionflags,
                 **self.additional_options
@@ -103,7 +115,6 @@
             '%s [%s]' % (DefaultZCMLLayer.__name__, zcml_file))
         return layer
 
-
     def isTestFile(self, filepath):
         """Return ``True`` if a file matches our expectations for a
         doctest file.



More information about the Checkins mailing list