[testlib] properly close connections opened during test in tearDown stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 07 Apr 2010 14:42:12 +0200
branchstable
changeset 5175 6efb7a7ae570
parent 5172 865a3e522add
child 5177 395e1ff018ae
child 5178 42285e33b01c
[testlib] properly close connections opened during test in tearDown
devtools/testlib.py
--- a/devtools/testlib.py	Wed Apr 07 11:57:37 2010 +0200
+++ b/devtools/testlib.py	Wed Apr 07 14:42:12 2010 +0200
@@ -261,6 +261,12 @@
         self.setup_database()
         self.commit()
         MAILBOX[:] = [] # reset mailbox
+        self._cnxs = []
+
+    def tearDown(self):
+        for cnx in self._cnxs:
+            if not cnx._closed:
+                cnx.close()
 
     def setup_database(self):
         """add your database setup code by overriding this method"""
@@ -302,6 +308,7 @@
             self.cnx = repo_connect(self.repo, unicode(login),
                                     cnxprops=ConnectionProperties('inmemory'),
                                     **kwargs)
+            self._cnxs.append(self.cnx)
         if login == self.vreg.config.anonymous_user()[0]:
             self.cnx.anonymous_connection = True
         return self.cnx
@@ -310,6 +317,7 @@
         if not self.cnx is self._orig_cnx:
             try:
                 self.cnx.close()
+                self._cnxs.remove(self.cnx)
             except ProgrammingError:
                 pass # already closed
         self.cnx = self._orig_cnx