From defb428339ee460daea85673ac9bca866b0fea69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 23 Jan 2023 23:00:29 +0100 Subject: [PATCH] Do not register tests module when pool is not started for testing Closes #6846 --- trytond/trytond/ir/module.py | 2 +- trytond/trytond/ir/ui/view.py | 2 +- trytond/trytond/modules/__init__.py | 14 ++++++++------ trytond/trytond/pool.py | 2 +- trytond/trytond/tests/test_tryton.py | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/trytond/trytond/ir/module.py b/trytond/trytond/ir/module.py index 7f18cbd2c8..cbebae1557 100644 --- a/trytond/trytond/ir/module.py +++ b/trytond/trytond/ir/module.py @@ -279,7 +279,7 @@ class Module(ModelSQL, ModelView): def update_list(cls): 'Update the list of available packages' count = 0 - module_names = get_module_list() + module_names = get_module_list(with_test=Pool.test) modules = cls.search([]) name2id = dict((m.name, m.id) for m in modules) diff --git a/trytond/trytond/ir/ui/view.py b/trytond/trytond/ir/ui/view.py index 7e54225d42..249c30afcf 100644 --- a/trytond/trytond/ir/ui/view.py +++ b/trytond/trytond/ir/ui/view.py @@ -223,7 +223,7 @@ class View(ModelSQL, ModelView): def _module_index(self): from trytond.modules import create_graph, get_module_list if self.__class__.__module_index is None: - graph = create_graph(get_module_list()) + graph = create_graph(get_module_list(with_test=Pool.test)) modules = [m.name for m in graph] self.__class__.__module_index = { m: i for i, m in enumerate(reversed(modules))} diff --git a/trytond/trytond/modules/__init__.py b/trytond/trytond/modules/__init__.py index 8cb7585ca0..1303a5a5da 100644 --- a/trytond/trytond/modules/__init__.py +++ b/trytond/trytond/modules/__init__.py @@ -318,7 +318,7 @@ def load_module_graph(graph, pool, update=None, lang=None): logger.info('all modules loaded') -def get_module_list(): +def get_module_list(with_test=False): module_list = set() if os.path.exists(MODULES_PATH) and os.path.isdir(MODULES_PATH): for file in os.listdir(MODULES_PATH): @@ -332,11 +332,12 @@ def get_module_list(): module_list.update(EGG_MODULES.keys()) module_list.add('ir') module_list.add('res') - module_list.add('tests') + if with_test: + module_list.add('tests') return list(module_list) -def register_classes(): +def register_classes(with_test=False): ''' Import modules to register the classes in the Pool ''' @@ -344,10 +345,11 @@ def register_classes(): trytond.ir.register() import trytond.res trytond.res.register() - import trytond.tests - trytond.tests.register() + if with_test: + import trytond.tests + trytond.tests.register() - for node in create_graph(get_module_list()): + for node in create_graph(get_module_list(with_test=with_test)): module = node.name logger.info('%s:registering classes', module) diff --git a/trytond/trytond/pool.py b/trytond/trytond/pool.py index 8d4c6af217..86cf972338 100644 --- a/trytond/trytond/pool.py +++ b/trytond/trytond/pool.py @@ -105,7 +105,7 @@ class Pool(object): with cls._lock: for classes in Pool.classes.values(): classes.clear() - register_classes() + register_classes(with_test=cls.test) cls._started = True @classmethod diff --git a/trytond/trytond/tests/test_tryton.py b/trytond/trytond/tests/test_tryton.py index 360cf251f2..a2a159d524 100644 --- a/trytond/trytond/tests/test_tryton.py +++ b/trytond/trytond/tests/test_tryton.py @@ -51,6 +51,7 @@ __all__ = [ 'with_transaction', ] +Pool.test = True Pool.start() USER = 1 CONTEXT = {} @@ -62,7 +63,6 @@ else: DB_NAME = 'test_' + str(int(time.time())) os.environ['DB_NAME'] = DB_NAME DB_CACHE = os.environ.get('DB_CACHE') -Pool.test = True def activate_module(modules, lang='en'):