From cc9113f818ad62c4bfc5ede90a1b055c8bb9414e Mon Sep 17 00:00:00 2001 From: dufresnedavid Date: Tue, 1 Sep 2015 17:10:33 -0400 Subject: [PATCH] [IMP] Prevent unclosed cursor during tests If an error happens in an overload of setUp, the already-open cursor is likely not to get properly released before the next test, deadlocking the db, because tearDown only runs if setUp has succesfully completed. Cleanups were added specifically to run every time, after tearDown has (potentially) been executed. closes #8327 Note: cleanups run in LIFO order (as they should). --- openerp/tests/common.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openerp/tests/common.py b/openerp/tests/common.py index 3f0143ef9df..4e72b6c5fd6 100644 --- a/openerp/tests/common.py +++ b/openerp/tests/common.py @@ -94,9 +94,10 @@ class TransactionCase(BaseCase): TransactionCase.cr = self.cursor() TransactionCase.uid = openerp.SUPERUSER_ID - def tearDown(self): - self.cr.rollback() - self.cr.close() + @self.addCleanup + def close_cursor(): + self.cr.rollback() + self.cr.close() class SingleTransactionCase(BaseCase):