[testlib] don't wrap main test connection into TestCaseConnectionProxy, it should not be closed afterwards
--- 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]: