[Zope3-checkins] SVN: Zope3/trunk/src/zope/testing/doctestunit.py Modification to DocFileSuite to use sensible names for the test functions it creates. The motivation for this is to support matching of function names specified when running tests. E.g., a doctest in file 'foo.txt' can run using:

Garrett Smith garrett at mojave-corp.com
Wed Jun 16 13:15:35 EDT 2004


Log message for revision 25883:
Modification to DocFileSuite to use sensible names for the test functions it creates. The motivation for this is to support matching of function names specified when running tests. E.g., a doctest in file 'foo.txt' can run using:

  python test.py . foo_txt



-=-
Modified: Zope3/trunk/src/zope/testing/doctestunit.py
===================================================================
--- Zope3/trunk/src/zope/testing/doctestunit.py	2004-06-16 16:36:44 UTC (rev 25882)
+++ Zope3/trunk/src/zope/testing/doctestunit.py	2004-06-16 17:15:35 UTC (rev 25883)
@@ -94,6 +94,12 @@
     
     Each subsequent argument is a string specifying the file name of the
     doctest relative to the package.
+    
+    The suite contains one function test case (unittest.FunctionTestCase) for 
+    each doctest source file. The function name is derrived from the doctest
+    file name by replacing '.' characters with '_'. E.g. if the doctest file is
+    'utility.txt' and the package is foo.bar, the test function name will be 
+    'foo.bar.utility_txt'.
     """
     
     # It's not entirely obvious how to connection this single string
@@ -106,11 +112,14 @@
     suite = unittest.TestSuite()
     dir = os.path.split(package.__file__)[0]
     for path in paths:
+        from re import sub
+        funcName = path.replace('.', '_')
+        funcName = package.__name__ + '.' + sub('\\\|/', '.', funcName)
         path = os.path.join(dir, path)
         source = open(path).read()
         def runit(path=path, source=source):
             doctest._utest(t, path, source, path, 0)
-        runit = new.function(runit.func_code, runit.func_globals, path,
+        runit = new.function(runit.func_code, runit.func_globals, funcName,
                              runit.func_defaults, runit.func_closure)
         f = unittest.FunctionTestCase(runit,
                                       description="doctest from %s" % path)




More information about the Zope3-Checkins mailing list