devtools/testlib.py
changeset 5177 395e1ff018ae
parent 5174 78438ad513ca
parent 5175 6efb7a7ae570
child 5223 6abd6e3599f4
--- a/devtools/testlib.py	Wed Apr 07 14:42:44 2010 +0200
+++ b/devtools/testlib.py	Wed Apr 07 14:42:55 2010 +0200
@@ -265,6 +265,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"""
@@ -306,6 +312,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
@@ -314,6 +321,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