[testlib] don't wrap main test connection into TestCaseConnectionProxy, it should not be closed afterwards stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 27 Sep 2010 17:14:23 +0200
branchstable
changeset 6346 1a968e545e4e
parent 6345 1a7f4bfbf92b
child 6347 ef47a2100c66
[testlib] don't wrap main test connection into TestCaseConnectionProxy, it should not be closed afterwards
devtools/testlib.py
--- a/devtools/testlib.py	Mon Sep 27 17:13:41 2010 +0200
+++ b/devtools/testlib.py	Mon Sep 27 17:14:23 2010 +0200
@@ -347,15 +347,19 @@
         """return a connection for the given login/password"""
         if login == self.admlogin:
             self.restore_connection()
-        else:
-            if not kwargs:
-                kwargs['password'] = str(login)
-            self.cnx = repo_connect(self.repo, unicode(login), **kwargs)
-            self.websession = DBAPISession(self.cnx)
-            self._cnxs.append(self.cnx)
+            # definitly don't want autoclose when used as a context manager
+            return self.cnx
+        autoclose = kwargs.pop('autoclose', True)
+        if not kwargs:
+            kwargs['password'] = str(login)
+        self.cnx = repo_connect(self.repo, unicode(login), **kwargs)
+        self.websession = DBAPISession(self.cnx)
+        self._cnxs.append(self.cnx)
         if login == self.vreg.config.anonymous_user()[0]:
             self.cnx.anonymous_connection = True
-        return TestCaseConnectionProxy(self, self.cnx)
+        if autoclose:
+            return TestCaseConnectionProxy(self, self.cnx)
+        return self.cnx
 
     def restore_connection(self):
         if not self.cnx is self._orig_cnx[0]: