From 1cfaa1201228ffc96189ef9fe7858d9708dc5a43 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 21 Aug 2018 18:10:58 +0200 Subject: [PATCH] [IMP] server: --test-enable support tests directory without import Before this commit, if import from tests directory was not in the __init__ file, it was not possible to launch it with --test-file cli. Now we only check in test directory if file exists. This commit closes #26500 --- addons/account/__init__.py | 1 - addons/point_of_sale/__init__.py | 1 - odoo/service/server.py | 9 +++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/account/__init__.py b/addons/account/__init__.py index 5c2e72f503c..866c39de02e 100644 --- a/addons/account/__init__.py +++ b/addons/account/__init__.py @@ -5,7 +5,6 @@ from . import controllers from . import models from . import wizard from . import report -from . import tests from odoo import api, SUPERUSER_ID diff --git a/addons/point_of_sale/__init__.py b/addons/point_of_sale/__init__.py index 0c674f48dfc..ee87c280f2c 100644 --- a/addons/point_of_sale/__init__.py +++ b/addons/point_of_sale/__init__.py @@ -5,4 +5,3 @@ from . import models from . import controllers from . import report from . import wizard -from . import tests diff --git a/odoo/service/server.py b/odoo/service/server.py index 92f63086c63..26d05ecb03a 100644 --- a/odoo/service/server.py +++ b/odoo/service/server.py @@ -36,7 +36,8 @@ except ImportError: setproctitle = lambda x: None import odoo -from odoo.modules.module import run_unit_tests +from odoo.modules import get_modules +from odoo.modules.module import run_unit_tests, get_test_modules from odoo.modules.registry import Registry from odoo.release import nt_service_name from odoo.tools import config @@ -891,10 +892,9 @@ def _reexec(updated_modules=None): os.execve(sys.executable, args, os.environ) def load_test_file_py(registry, test_file): - # Locate python module based on its filename and run the tests test_path, _ = os.path.splitext(os.path.abspath(test_file)) - for mod_name, mod_mod in list(sys.modules.items()): - if mod_mod: + for mod in [m for m in get_modules() if '/%s/' % m in test_file]: + for mod_mod in get_test_modules(mod): mod_path, _ = os.path.splitext(getattr(mod_mod, '__file__', '')) if test_path == mod_path: suite = unittest.TestSuite() @@ -908,6 +908,7 @@ def load_test_file_py(registry, test_file): registry._assertion_report.report_result(success) if not success: _logger.error('%s: at least one error occurred in a test', test_file) + return def preload_registries(dbnames): """ Preload a registries, possibly run a test file."""