From 2caaa67cae3de2a385932ecd370cccdfe712a51a Mon Sep 17 00:00:00 2001 From: SOUVIK GHOSH Date: Tue, 11 Jul 2023 12:35:59 +0200 Subject: [PATCH] fix: logger message to debug when plugins not found (#995) * fix: logger message to debug when plugins not found * add changelog and test * fix:lint error * fix:lint error * amend test and log format --------- Co-authored-by: Anca Lita <27920906+ancalita@users.noreply.github.com> --- changelog/1219.bugfix.md | 1 + rasa_sdk/plugin.py | 2 +- tests/test_plugin.py | 13 ++++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 changelog/1219.bugfix.md diff --git a/changelog/1219.bugfix.md b/changelog/1219.bugfix.md new file mode 100644 index 000000000..e53471204 --- /dev/null +++ b/changelog/1219.bugfix.md @@ -0,0 +1 @@ +The logger for rasa_sdk plugin will not throw traceback when no plugins are found since plugins are optional. It will be only available in debug mode, however the action server will continue to run. \ No newline at end of file diff --git a/rasa_sdk/plugin.py b/rasa_sdk/plugin.py index 217ddecb7..462abc552 100644 --- a/rasa_sdk/plugin.py +++ b/rasa_sdk/plugin.py @@ -27,7 +27,7 @@ def _discover_plugins(manager: pluggy.PluginManager) -> None: rasa_sdk_plugins.init_hooks(manager) except ModuleNotFoundError as e: - logger.info("No plugins found", exc_info=e) + logger.debug("No plugins found: %s", e) pass diff --git a/tests/test_plugin.py b/tests/test_plugin.py index ecd0d8564..c984f7e73 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1,6 +1,7 @@ +import logging import warnings -from pytest import MonkeyPatch +from pytest import MonkeyPatch, LogCaptureFixture from pluggy import PluginManager from unittest.mock import MagicMock @@ -8,6 +9,16 @@ from rasa_sdk.plugin import plugin_manager +def test_plugins_not_found(caplog: LogCaptureFixture) -> None: + """Test that a debug message is logged when no plugins are found. + + This test must be run first because the plugin manager is cached. + """ + with caplog.at_level(logging.DEBUG): + plugin_manager() + assert "No plugins found: No module named 'rasa_sdk_plugins'" in caplog.text + + def test_plugin_manager() -> None: manager = plugin_manager() assert isinstance(manager, PluginManager)