Commit 469966dc authored by Barry Warsaw's avatar Barry Warsaw

Two changes to ensure that we remove the test-db file when an error

occurs.  First, inherit from BerkeleyTestBase which has proper setUp
and tearDown methods, and second, wrap the .abort() and ._close() call
in tearDown() in a try/finally so we're guaranteed that the base
class's tearDown gets run.
parent 779aa469
...@@ -16,18 +16,17 @@ ...@@ -16,18 +16,17 @@
import os import os
import errno import errno
import unittest
from ZODB import DB from ZODB import DB
from bsddb3Storage.tests.BerkeleyTestBase import BerkeleyTestBase
DBHOME = 'test-db' DBHOME = 'test-db'
class ZODBTestBase(unittest.TestCase): class ZODBTestBase(BerkeleyTestBase):
def setUp(self): def setUp(self):
os.mkdir(DBHOME) BerkeleyTestBase.setUp(self)
try: try:
self._storage = self.ConcreteStorage(DBHOME) self._storage = self.ConcreteStorage(DBHOME)
self._db = DB(self._storage) self._db = DB(self._storage)
...@@ -45,8 +44,8 @@ class ZODBTestBase(unittest.TestCase): ...@@ -45,8 +44,8 @@ class ZODBTestBase(unittest.TestCase):
# subsequent tests because the next transaction commit will try to # subsequent tests because the next transaction commit will try to
# commit those object. But they're tied to closed databases, so # commit those object. But they're tied to closed databases, so
# that's broken. Aborting the transaction now saves us the headache. # that's broken. Aborting the transaction now saves us the headache.
try:
get_transaction().abort() get_transaction().abort()
self._close() self._close()
for file in os.listdir(DBHOME): finally:
os.unlink(os.path.join(DBHOME, file)) BerkeleyTestBase.tearDown(self)
os.removedirs(DBHOME)
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