[devtools] properly close open access on tearDown
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 03 Apr 2014 18:12:48 +0200
changeset 9628 2997f81cde19
parent 9627 91166f6fd2c9
child 9629 8114bed10e78
[devtools] properly close open access on tearDown avoiding further warning about living sessions while the repo is turned off. The doc string says: The RepoAccess need to be closed to destroy the associated Session. TestCase usually take care of this aspect for the user. but that wasn't true until now.
devtools/testlib.py
--- a/devtools/testlib.py	Thu Apr 03 19:10:40 2014 +0200
+++ b/devtools/testlib.py	Thu Apr 03 18:12:48 2014 +0200
@@ -40,7 +40,7 @@
 from logilab.common.shellutils import getlogin
 
 from cubicweb import (ValidationError, NoSelectableObject, AuthenticationError,
-                      ProgrammingError)
+                      ProgrammingError, BadConnectionId)
 from cubicweb import cwconfig, devtools, web, server, repoapi
 from cubicweb.utils import json
 from cubicweb.sobjects import notification
@@ -297,7 +297,10 @@
 
     def _close_access(self):
         while self._open_access:
-            self._open_access.pop().close()
+            try:
+                self._open_access.pop().close()
+            except BadConnectionId:
+                continue # already closed
 
     @deprecated('[3.19] explicitly use RepoAccess object in test instead')
     def set_cnx(self, cnx):
@@ -552,6 +555,7 @@
         except Exception as ex:
             self.__class__._repo_init_failed = ex
             raise
+        self.addCleanup(self._close_access)
         resume_tracing()
         self.setup_database()
         self._admin_clt_cnx.commit()