From 583d09148948c7891fdfc68a0b07cc60f345e711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 28 Feb 2023 09:34:07 +0100 Subject: [PATCH 1/3] [IMP] module_analysis: Change with Environment.manage() --- module_analysis/post_init_hook.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/module_analysis/post_init_hook.py b/module_analysis/post_init_hook.py index e509c55f3..3e3b86ef0 100644 --- a/module_analysis/post_init_hook.py +++ b/module_analysis/post_init_hook.py @@ -6,9 +6,8 @@ from odoo import SUPERUSER_ID, api def analyse_installed_modules(cr, registry): - with api.Environment.manage(): - env = api.Environment(cr, SUPERUSER_ID, {}) - installed_modules = env["ir.module.module"].search( - ["|", ("state", "=", "installed"), ("name", "=", "module_analysis")] - ) - installed_modules.button_analyse_code() + env = api.Environment(cr, SUPERUSER_ID, {}) + installed_modules = env["ir.module.module"].search( + ["|", ("state", "=", "installed"), ("name", "=", "module_analysis")] + ) + installed_modules.button_analyse_code() From a41725cf75e88017188c70632452c589fa45bdf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 27 Feb 2023 17:40:52 +0100 Subject: [PATCH 2/3] [FIX] module_analysis: Fix tests Prevent import error ImportError: cannot import name 'at_install' from 'odoo.tests.common' (/opt/odoo/odoo/tests/common.py) --- module_analysis/tests/test_module.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/module_analysis/tests/test_module.py b/module_analysis/tests/test_module.py index 2908d0f95..6769c8b7d 100644 --- a/module_analysis/tests/test_module.py +++ b/module_analysis/tests/test_module.py @@ -2,11 +2,10 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests.common import TransactionCase, at_install, post_install +from odoo.tests.common import TransactionCase, tagged -@at_install(False) -@post_install(True) +@tagged("-at_install", "post_install") class TestModule(TransactionCase): def setUp(self): super().setUp() From 31a20cfd6358c9a2b5236e6973d7cd19dfb539a3 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Thu, 18 May 2023 11:46:08 +0200 Subject: [PATCH 3/3] [FIX] module_analysis : tests compatibility with pip install --- module_analysis/tests/test_module.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/module_analysis/tests/test_module.py b/module_analysis/tests/test_module.py index 6769c8b7d..811eaebd9 100644 --- a/module_analysis/tests/test_module.py +++ b/module_analysis/tests/test_module.py @@ -7,9 +7,16 @@ from odoo.tests.common import TransactionCase, tagged @tagged("-at_install", "post_install") class TestModule(TransactionCase): - def setUp(self): - super().setUp() - self.IrModuleModule = self.env["ir.module.module"] + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.IrModuleModule = cls.env["ir.module.module"] + # Remove lib because it breaks tests in case of installation of modules with + # pip + cls.env["ir.config_parameter"].set_param( + "module_analysis.exclude_directories", "demo,test,tests,doc,description" + ) + cls.IrModuleModule.cron_analyse_code() def test_installed_modules(self): installed_modules = self.IrModuleModule.search(