[Zope3-checkins] CVS: Zope3/src/zope/testing - doctestunit.py:1.4

Jim Fulton jim at zope.com
Sun Sep 21 13:34:29 EDT 2003


Update of /cvs-repository/Zope3/src/zope/testing
In directory cvs.zope.org:/tmp/cvs-serv16095/src/zope/testing

Modified Files:
	doctestunit.py 
Log Message:
Added the ability to pass setup and teardoen functions.


=== Zope3/src/zope/testing/doctestunit.py 1.3 => 1.4 ===
--- Zope3/src/zope/testing/doctestunit.py:1.3	Sun Jun 29 01:07:50 2003
+++ Zope3/src/zope/testing/doctestunit.py	Sun Sep 21 13:34:29 2003
@@ -30,7 +30,10 @@
 class DocTestTestFailure(Exception):
     """A doctest test failed"""
 
-def DocTestSuite(module=None):
+def DocTestSuite(module=None,
+                 setUp=lambda: None,
+                 tearDown=lambda: None,
+                 ):
     """Convert doctest tests for a mudule to a unittest test suite
 
     This tests convers each documentation string in a module that
@@ -61,9 +64,16 @@
                 filename = filename[:-1]
             elif filename.endswith(".pyo"):
                 filename = filename[:-1]
+
+        def testfunc(args=(tester, name, doc, filename, lineno)):
+            setUp()
+            try:
+                _test(*args)
+            finally:
+                tearDown()
+                
         suite.addTest(unittest.FunctionTestCase(
-            lambda args=(tester, name, doc, filename, lineno):
-            _test(*args),
+            testfunc,
             description = "doctest of "+name
             ))
 




More information about the Zope3-Checkins mailing list