[Checkins] SVN: ZODB/trunk/src/ZODB/tests/util.py Added common setUp and tearDown for both doctests and unittest tests

Jim Fulton jim at zope.com
Tue Oct 28 17:33:19 EDT 2008


Log message for revision 92660:
  Added common setUp and tearDown for both doctests and unittest tests
  to abort the current global transaction before and after each test and
  to create a temporary test directory to run each test.
  

Changed:
  U   ZODB/trunk/src/ZODB/tests/util.py

-=-
Modified: ZODB/trunk/src/ZODB/tests/util.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/util.py	2008-10-28 19:08:43 UTC (rev 92659)
+++ ZODB/trunk/src/ZODB/tests/util.py	2008-10-28 21:33:18 UTC (rev 92660)
@@ -16,10 +16,41 @@
 $Id$
 """
 
+from ZODB.MappingStorage import DB
+
+import os
+import tempfile
 import time
+import unittest
 import persistent
-from ZODB.MappingStorage import DB
+import transaction
+import zope.testing.setupstack
 
+def setUp(test, name='test'):
+    transaction.abort()
+    d = tempfile.mkdtemp(prefix=name)
+    zope.testing.setupstack.register(test, zope.testing.setupstack.rmtree, d)
+    zope.testing.setupstack.register(
+        test, setattr, tempfile, 'tempdir', tempfile.tempdir)
+    tempfile.tempdir = d
+    zope.testing.setupstack.register(test, os.chdir, os.getcwd())
+    os.chdir(d)
+    zope.testing.setupstack.register(test, transaction.abort)
+
+tearDown = zope.testing.setupstack.tearDown
+
+class TestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.globs = {}
+        name = self.__class__.__name__
+        mname = getattr(self, '_TestCase__testMethodName', '')
+        if mname:
+            name += '-' + mname
+        setUp(self, name)
+
+    tearDown = tearDown
+
 def pack(db):
     db.pack(time.time()+1)
 



More information about the Checkins mailing list