[Checkins] SVN: megrok.rdb/trunk/src/megrok/rdb/ Found a way to work around the __builtin__ issue.

Martijn Faassen faassen at infrae.com
Wed Jun 25 16:54:22 EDT 2008


Log message for revision 87776:
  Found a way to work around the __builtin__ issue.
  

Changed:
  U   megrok.rdb/trunk/src/megrok/rdb/README.txt
  U   megrok.rdb/trunk/src/megrok/rdb/tests.py

-=-
Modified: megrok.rdb/trunk/src/megrok/rdb/README.txt
===================================================================
--- megrok.rdb/trunk/src/megrok/rdb/README.txt	2008-06-25 20:53:43 UTC (rev 87775)
+++ megrok.rdb/trunk/src/megrok/rdb/README.txt	2008-06-25 20:54:21 UTC (rev 87776)
@@ -160,17 +160,6 @@
   
   >>> session = rdb.Session()
 
-To make the next bit work with doctests, we need an utter hack::
-
-  >>> Courses.__module__ = 'foo' 
-
-This is only because ``Courses`` is defined in a doctest. Because of
-this, the ``__module__`` attribute of of ``Courses`` will be set to
-``__builtin__``, and SQLAlchemy then concludes that ``Courses`` is
-really a builtin Python object and refuses to instrument it
-propertly. By changing ``__module__`` to something else, we avoid this
-problem.
-
 Let's now create a database structure. We have a department of philosophy::
 
   >>> philosophy = Department(name="Philosophy")

Modified: megrok.rdb/trunk/src/megrok/rdb/tests.py
===================================================================
--- megrok.rdb/trunk/src/megrok/rdb/tests.py	2008-06-25 20:53:43 UTC (rev 87775)
+++ megrok.rdb/trunk/src/megrok/rdb/tests.py	2008-06-25 20:54:21 UTC (rev 87776)
@@ -1,8 +1,15 @@
 import unittest
 import doctest
 from zope.testing import cleanup
+from zope.testing import module
 
+def setUp(test):
+    # using zope.testing.module.setUp to work around
+    # __module__ being '__builtin__' by default
+    module.setUp(test, '__main__')
+    
 def tearDown(test):
+    module.tearDown(test)
     cleanup.cleanUp()
 
     # XXX clean up SQLAlchemy?
@@ -16,6 +23,7 @@
     suite.addTest(doctest.DocFileSuite(
         'README.txt',
         optionflags=optionflags,
+        setUp=setUp,
         tearDown=tearDown,
         globs=globs))
     return suite



More information about the Checkins mailing list