From 53524d9077800f2f85c9462959b0533c41e79233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Tue, 18 Jan 2022 11:50:42 +0100 Subject: [PATCH] chore: refactor clear_cache code --- tests/test_plugins.py | 2 +- tutor/plugins.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 2d30d57..8bb9ba3 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -8,7 +8,7 @@ from tutor.types import Config, get_typed class PluginsTests(unittest.TestCase): def setUp(self) -> None: - plugins.Plugins.clear() + plugins.Plugins.clear_cache() @patch.object(plugins.DictPlugin, "iter_installed", return_value=[]) def test_iter_installed(self, dict_plugin_iter_installed: Mock) -> None: diff --git a/tutor/plugins.py b/tutor/plugins.py index ab33979..c7d23fc 100644 --- a/tutor/plugins.py +++ b/tutor/plugins.py @@ -182,6 +182,11 @@ class BasePlugin: def iter_load(cls) -> Iterator["BasePlugin"]: raise NotImplementedError + @classmethod + def clear_cache(cls) -> None: + cls._IS_LOADED = False + cls.INSTALLED.clear() + class EntrypointPlugin(BasePlugin): """ @@ -324,9 +329,9 @@ class Plugins: self.hooks[hook_name][plugin.name] = services @classmethod - def clear(cls) -> None: + def clear_cache(cls) -> None: for PluginClass in cls.PLUGIN_CLASSES: - PluginClass.INSTALLED.clear() + PluginClass.clear_cache() @classmethod def iter_installed(cls) -> Iterator[BasePlugin]: