Commit 59188e56 authored by Jim Fulton's avatar Jim Fulton

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.
parent 85afb467
......@@ -16,9 +16,40 @@
$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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment