diff options
| author | Raphael Collet <rco@odoo.com> | 2019-09-24 08:45:54 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2019-09-24 08:45:54 +0000 |
| commit | e4fc7568c1252bb9fe68f52411f99d132ec3b94f (patch) | |
| tree | 9c9029bfb2bdd6e85b9d8477f418280eb9ceb0b0 /odoo/tests | |
| parent | a15d3a710c2f27594d658806055f1c62e092bb44 (diff) | |
[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>
Diffstat (limited to 'odoo/tests')
| -rw-r--r-- | odoo/tests/common.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/odoo/tests/common.py b/odoo/tests/common.py index 706626394db..59c4cd334b5 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -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) |
