diff --git a/odoo/tests/loader.py b/odoo/tests/loader.py index 2d6c2d8275d3a4cf3967140c4077e3298aeaaca2..e435aa98c823537ac30ff0cc74559575b2666e6b 100644 --- a/odoo/tests/loader.py +++ b/odoo/tests/loader.py @@ -2,8 +2,10 @@ import importlib import inspect import itertools import logging +import sys import threading import unittest +from pathlib import Path from .. import tools from .common import TagsSelector, OdooSuite @@ -22,7 +24,7 @@ def get_test_modules(module): except ImportError: pass else: - results += _get_tests_modules('odoo.upgrade', module) + results += list(_get_upgrade_test_modules(module)) return results @@ -50,6 +52,19 @@ def _get_tests_modules(path, module): if name.startswith('test_')] return result +def _get_upgrade_test_modules(module): + upg = importlib.import_module("odoo.upgrade") + for path in map(Path, upg.__path__): + for test in (path / module / "tests").glob("test_*.py"): + spec = importlib.util.spec_from_file_location(f"odoo.upgrade.{module}.tests.{test.stem}", test) + if not spec: + continue + pymod = importlib.util.module_from_spec(spec) + sys.modules[spec.name] = pymod + spec.loader.exec_module(pymod) + yield pymod + + def make_suite(module_name, position='at_install'): mods = get_test_modules(module_name) """ Creates a test suite for all the tests in the specified module,