diff --git a/rasa_sdk/plugin.py b/rasa_sdk/plugin.py index 44ac209a4..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.debug("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 742d16e4d..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) @@ -38,17 +49,3 @@ def test_plugin_attach_sanic_app_extension( warnings.simplefilter("error") endpoint.run("actions") manager.hook.attach_sanic_app_extensions.assert_called_once_with(app=app_mock) - - -def test_plugins_not_found(monkeypatch): - # Mock the import statement to raise ModuleNotFoundError - monkeypatch.setitem( - __builtins__, "import", MagicMock(side_effect=ModuleNotFoundError) - ) - - # Call the method under test - try: - import rasa_sdk_plugins - except ModuleNotFoundError as e: - # Assert the expected exception message or other details if needed - assert str(e) == "No module named 'rasa_sdk_plugins'"