[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).
This commit is contained in:
dufresnedavid 2015-09-01 17:10:33 -04:00 committed by Xavier Morel
parent acf22b7bc8
commit cc9113f818
1 changed files with 4 additions and 3 deletions

View File

@ -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):