From d43b36f90cb1a3af889d2b2c37b77534e0617ff6 Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Fri, 4 Feb 2022 18:13:46 +0100 Subject: [PATCH] throw exception instance not class and add test --- amqtt/plugins/logging.py | 2 +- tests/plugins/test_logging.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/plugins/test_logging.py diff --git a/amqtt/plugins/logging.py b/amqtt/plugins/logging.py index 1c6ef18..bc44723 100644 --- a/amqtt/plugins/logging.py +++ b/amqtt/plugins/logging.py @@ -19,7 +19,7 @@ class EventLoggerPlugin: def __getattr__(self, name): if name.startswith("on_"): return partial(self.log_event, event_name=name) - raise AttributeError + raise AttributeError(f"'EventLoggerPlugin' object has no attribute {name!r}") class PacketLoggerPlugin: diff --git a/tests/plugins/test_logging.py b/tests/plugins/test_logging.py new file mode 100644 index 0000000..5fef6a8 --- /dev/null +++ b/tests/plugins/test_logging.py @@ -0,0 +1,11 @@ +import pytest + +import amqtt.plugins.logging + + +def test_EventLoggerPlugin_getattr(): + logger = amqtt.plugins.logging.EventLoggerPlugin(None) + with pytest.raises(AttributeError) as exc: + logger.foo + + assert "foo" in str(exc.value)