Commit 5abb074d authored by Vincent Pelletier's avatar Vincent Pelletier

ERP5TypeTestCase: Close ZMySQLDA connections during tearDown.

Avoids accumulating useless connections when a single test file contains
multiple files.
parent c02f8a26
......@@ -28,6 +28,8 @@ from hashlib import md5
from warnings import warn
from ExtensionClass import pmc_init_of
from DateTime import DateTime
import Products.ZMySQLDA.DA
from Products.ZMySQLDA.DA import Connection as ZMySQLDA_Connection
# XXX make sure that get_request works.
from new import function
......@@ -818,6 +820,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start))
class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
__original_ZMySQLDA_connect = None
def addERP5TypeTestCaseUser(self, password=None, **kw):
return super(ERP5TypeCommandLineTestCase, self).addERP5TypeTestCaseUser(password='', **kw)
......@@ -901,11 +904,21 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
return uninstalled_list
def __onConnect(self, connector):
def setUp(self):
'''Sets up the fixture. Do not override,
use the hooks instead.
from Products.CMFActivity.ActivityRuntimeEnvironment import BaseMessage
self.__connector_set = set()
onConnect = self.__onConnect
self.__original_ZMySQLDA_connect = original_ZMySQLDA_connect = ZMySQLDA_Connection.connect
def connect(self, *args, **kw):
return original_ZMySQLDA_connect(self, *args, **kw)
ZMySQLDA_Connection.connect = connect
# Activities in unit tests shall never fail.
# Let's be a litte tolerant for the moment.
BaseMessage.max_retry = property(lambda self:
......@@ -1276,6 +1289,14 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
% count)
if self.__original_ZMySQLDA_connect is not None:
ZMySQLDA_Connection.connect = self.__original_ZMySQLDA_connect
for connector in self.__connector_set:
connector.__dict__.pop('_v_database_connection', None)
database_connection_pool = Products.ZMySQLDA.DA.database_connection_pool
for value in database_connection_pool.itervalues():
def importObjectFromFile(self, container, relative_path, **kw):
"""Import an object from a file located in $TESTFILEDIR/input/"""
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