From 852aa5ae317ff9e2f44ea683811340af45de94b6 Mon Sep 17 00:00:00 2001 From: Christophe Monniez <moc@odoo.com> Date: Tue, 23 Feb 2021 07:50:32 +0000 Subject: [PATCH] [FIX] tests: add a linter to check for __init__.py in modules When a module is added, it happens that the `__init__.py` file is forgotten. In that case, those modules are not packaged. With this commit, a test is added to check that each Odoo module has the file. X-original-commit: edabed7b3ab351c76b9555378efa6258f9e76733 --- odoo/addons/test_lint/tests/__init__.py | 1 + .../addons/test_lint/tests/test_dunderinit.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 odoo/addons/test_lint/tests/test_dunderinit.py diff --git a/odoo/addons/test_lint/tests/__init__.py b/odoo/addons/test_lint/tests/__init__.py index c28bef7f1079..b8416fe62bfb 100644 --- a/odoo/addons/test_lint/tests/__init__.py +++ b/odoo/addons/test_lint/tests/__init__.py @@ -3,3 +3,4 @@ from . import test_pofile from . import test_ecmascript from . import test_markers from . import test_onchange_domains +from . import test_dunderinit diff --git a/odoo/addons/test_lint/tests/test_dunderinit.py b/odoo/addons/test_lint/tests/test_dunderinit.py new file mode 100644 index 000000000000..a074896832c5 --- /dev/null +++ b/odoo/addons/test_lint/tests/test_dunderinit.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging +from pathlib import Path + +from odoo.modules import get_modules, get_module_path +from . import lint_case + +_logger = logging.getLogger(__name__) + + +class TestDunderinit(lint_case.LintCase): + + def test_dunderinit(self): + """ Test that __init__.py exists in Odoo modules, otherwise they won't get packaged""" + + modules_list = get_modules() + for mod in modules_list: + dunderinit_path = Path(get_module_path(mod)) / '__init__.py' + self.assertTrue(dunderinit_path.is_file(), "Missing `__init__.py ` in module %s" % mod) + + _logger.info('%s modules checked', len(modules_list)) -- GitLab