From e885db8a50bedde3aedcc8eaa166f39a4a2b9c43 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 24 Oct 2018 15:11:51 +0200 Subject: [PATCH] [FIX] runbot_merge: make local tests run in v11 as well Runbot is supposed to run on v11, yet because the runbot_merge test suite was built on v12 due to an API change in Registry.enter_test_mode the (local) test suite would only run on v12. Add a conditional pick such that the test suite can run transparently on both v11 and v12. --- runbot_merge/tests/local.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/runbot_merge/tests/local.py b/runbot_merge/tests/local.py index db3b14dc..5e2a2fe9 100644 --- a/runbot_merge/tests/local.py +++ b/runbot_merge/tests/local.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import inspect import pytest import werkzeug.test, werkzeug.wrappers @@ -45,15 +46,26 @@ def registry(request): yield odoo.registry(db) @pytest.fixture -def env(registry): - with registry.cursor() as cr: - env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) - ctx = env['res.users'].context_get() - registry.enter_test_mode(cr) - yield env(context=ctx) +def cr(registry): + # in v12, enter_test_mode flags an existing cursor while in v11 it sets one up + if inspect.signature(registry.enter_test_mode).parameters: + with registry.cursor() as cr: + registry.enter_test_mode(cr) + yield cr + registry.leave_test_mode() + cr.rollback() + else: + registry.enter_test_mode() + with registry.cursor() as cr: + yield cr + cr.rollback() registry.leave_test_mode() - cr.rollback() +@pytest.fixture +def env(cr): + env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) + ctx = env['res.users'].context_get() + yield env(context=ctx) @pytest.fixture def owner():