From 2322a9806883a310826e1d43dc1c451a31dcf53d Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Wed, 14 Jun 2023 23:34:00 +0200 Subject: [PATCH] replace assertation with more targeted logging check (#5045) --- InvenTree/plugin/samples/event/event_sample.py | 6 ++++-- InvenTree/plugin/samples/event/test_event_sample.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/InvenTree/plugin/samples/event/event_sample.py b/InvenTree/plugin/samples/event/event_sample.py index 0b77932068..f6638cb480 100644 --- a/InvenTree/plugin/samples/event/event_sample.py +++ b/InvenTree/plugin/samples/event/event_sample.py @@ -1,12 +1,14 @@ """Sample plugin which responds to events.""" -import warnings +import logging from django.conf import settings from plugin import InvenTreePlugin from plugin.mixins import EventMixin +logger = logging.getLogger('inventree') + class EventPluginSample(EventMixin, InvenTreePlugin): """A sample plugin which provides supports for triggered events.""" @@ -23,4 +25,4 @@ class EventPluginSample(EventMixin, InvenTreePlugin): # Issue warning that we can test for if settings.PLUGIN_TESTING: - warnings.warn(f'Event `{event}` triggered', stacklevel=2) + logger.debug(f'Event `{event}` triggered in sample plugin') diff --git a/InvenTree/plugin/samples/event/test_event_sample.py b/InvenTree/plugin/samples/event/test_event_sample.py index 4f28e6595f..9085117716 100644 --- a/InvenTree/plugin/samples/event/test_event_sample.py +++ b/InvenTree/plugin/samples/event/test_event_sample.py @@ -8,6 +8,8 @@ from plugin.base.event.events import trigger_event from plugin.helpers import MixinNotImplementedError from plugin.mixins import EventMixin +from .event_sample import logger + class EventPluginSampleTests(TestCase): """Tests for EventPluginSample.""" @@ -22,9 +24,9 @@ class EventPluginSampleTests(TestCase): # Enable event testing settings.PLUGIN_TESTING_EVENTS = True # Check that an event is issued - with self.assertWarns(Warning) as cm: + with self.assertLogs(logger=logger, level="DEBUG") as cm: trigger_event('test.event') - self.assertEqual(cm.warning.args[0], 'Event `test.event` triggered') + self.assertIn('DEBUG:inventree:Event `test.event` triggered in sample plugin', cm[1]) # Disable again settings.PLUGIN_TESTING_EVENTS = False