devtools/testlib.py
changeset 5811 e77cea9721e7
parent 5752 b0bb553e3be4
parent 5786 7c16a4e7a592
child 5814 51cc4b61f9ae
--- a/devtools/testlib.py	Fri Jun 18 18:31:22 2010 +0200
+++ b/devtools/testlib.py	Mon Jun 21 13:23:11 2010 +0200
@@ -218,7 +218,10 @@
         if not 'repo' in cls.__dict__:
             cls._build_repo()
         else:
-            cls.cnx.rollback()
+            try:
+                cls.cnx.rollback()
+            except ProgrammingError:
+                pass
             cls._refresh_repo()
 
     @classmethod
@@ -280,6 +283,8 @@
         MAILBOX[:] = [] # reset mailbox
 
     def tearDown(self):
+        if not self.cnx._closed:
+            self.cnx.rollback()
         for cnx in self._cnxs:
             if not cnx._closed:
                 cnx.close()
@@ -330,11 +335,12 @@
 
     def restore_connection(self):
         if not self.cnx is self._orig_cnx[0]:
+            if not self.cnx._closed:
+                self.cnx.close()
             try:
-                self.cnx.close()
                 self._cnxs.remove(self.cnx)
-            except ProgrammingError:
-                pass # already closed
+            except ValueError:
+                pass
         self.cnx, self.websession = self._orig_cnx
 
     # db api ##################################################################
@@ -366,7 +372,7 @@
         try:
             self.cnx.rollback()
         except ProgrammingError:
-            pass
+            pass # connection closed
         finally:
             self.session.set_pool() # ensure pool still set after commit