[FIX] tests: clean up environments in SavepointCase
The following issue occurs nondeterministically: a test fails when trying to flush pending updates with a user id that does not exist. This only happens with `SavepointCase` tests. Here is the explanation: the method `cr.savepoint()` retrieves an environment to flush pending updates, and the chosen environment has a user that was created in another test, and thus no longer exists. The problem is that `Environments.envs` contains environments that are no longer supposed to be used. The solution consists in, after the test, discarding the environments that were not present before the test. closes odoo/odoo#37341 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
@@ -493,6 +493,11 @@ class SavepointCase(SingleTransactionCase):
|
||||
super(SavepointCase, self).setUp()
|
||||
self._savepoint_id = next(savepoint_seq)
|
||||
self.cr.execute('SAVEPOINT test_%d' % self._savepoint_id)
|
||||
# restore environments after the test to avoid invoking flush() with an
|
||||
# invalid environment (inexistent user id) from another test
|
||||
envs = self.env.all.envs
|
||||
self.addCleanup(envs.update, list(envs))
|
||||
self.addCleanup(envs.clear)
|
||||
|
||||
def tearDown(self):
|
||||
self.cr.execute('ROLLBACK TO SAVEPOINT test_%d' % self._savepoint_id)
|
||||
|
||||
Reference in New Issue
Block a user