From 0a48b5dfd459a87904944b21e272d7d315336093 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Wed, 18 Dec 2024 11:38:13 +0100 Subject: [PATCH] [IMP] extendable: Add backup/restore registry methods in test ExtendableMixin --- extendable/tests/common.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/extendable/tests/common.py b/extendable/tests/common.py index a883b27b1..05272e90e 100644 --- a/extendable/tests/common.py +++ b/extendable/tests/common.py @@ -7,7 +7,7 @@ from odoo import api from odoo.tests import common -from extendable import context +from extendable import context, main def _get_addon_name(full_name: str) -> str: @@ -53,6 +53,24 @@ def init_extendable_registry(cls): extendable_registry.init_registry([f"odoo.addons.{current_addon}.*"]) cls.token = context.extendable_registry.set(cls._extendable_registry) + @classmethod + def backup_extendable_registry(cls): + # Store the current extendable classes + cls._initial_extendable_class_defs_by_module = ( + main._extendable_class_defs_by_module + ) + # Use a copy of the current extendable classes + main._extendable_class_defs_by_module = dict( + cls._initial_extendable_class_defs_by_module + ) + + @classmethod + def restore_extendable_registry(cls): + # Restore the initial extendable classes + main._extendable_class_defs_by_module = ( + cls._initial_extendable_class_defs_by_module + ) + @classmethod def reset_extendable_registry(cls): context.extendable_registry.reset(cls.token)