Skip to content

Commit

Permalink
amend test and log format
Browse files Browse the repository at this point in the history
  • Loading branch information
ancalita committed Jul 11, 2023
1 parent 6cf1ac7 commit db43b84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rasa_sdk/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
27 changes: 12 additions & 15 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import logging
import warnings

from pytest import MonkeyPatch
from pytest import MonkeyPatch, LogCaptureFixture
from pluggy import PluginManager
from unittest.mock import MagicMock

from rasa_sdk import endpoint
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)
Expand Down Expand Up @@ -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'"

0 comments on commit db43b84

Please sign in to comment.