From f0b4baa70708fee45a0b11012d872c12a1c6a381 Mon Sep 17 00:00:00 2001 From: Thomas Bechtold <tbechtold@suse.com> Date: Tue, 4 Apr 2017 09:09:20 +0200 Subject: [PATCH] Mock 'oslo_messaging.notify._impl_routing.LOG' in notifier tests When running the tests with concurrency=1, 2 tests fail with: AttributeError: Mock object has no attribute 'debug' and AssertionError: Expected 'notify' to be called once. Called 0 times Mocking the LOG object solves the problem. Change-Id: Ie7f4448a103fae448123a05bc92e961aac00d6ec Closes-Bug: #1660393 --- oslo_messaging/tests/notify/test_notifier.py | 25 ++++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/oslo_messaging/tests/notify/test_notifier.py b/oslo_messaging/tests/notify/test_notifier.py index 31e62472d..7484311f9 100755 --- a/oslo_messaging/tests/notify/test_notifier.py +++ b/oslo_messaging/tests/notify/test_notifier.py @@ -441,10 +441,12 @@ group_2: with mock.patch('stevedore.dispatch.DispatchExtensionManager', return_value=self._fake_extension_manager( mock.MagicMock())): - self.router._load_notifiers() - groups = list(self.router.routing_groups.keys()) - groups.sort() - self.assertEqual(['group_1', 'group_2'], groups) + with mock.patch('oslo_messaging.notify.' + '_impl_routing.LOG'): + self.router._load_notifiers() + groups = list(self.router.routing_groups.keys()) + groups.sort() + self.assertEqual(['group_1', 'group_2'], groups) def test_get_drivers_for_message_accepted_events(self): config = r""" @@ -593,12 +595,15 @@ group_1: config_file): with mock.patch('stevedore.dispatch.DispatchExtensionManager', return_value=pm): - self.notifier.info({}, 'my_event', {}) - self.assertFalse(bar_driver.info.called) - rpc_driver.notify.assert_called_once_with( - {}, mock.ANY, 'INFO', None) - rpc2_driver.notify.assert_called_once_with( - {}, mock.ANY, 'INFO', None) + with mock.patch('oslo_messaging.notify.' + '_impl_routing.LOG'): + + self.notifier.info({}, 'my_event', {}) + self.assertFalse(bar_driver.info.called) + rpc_driver.notify.assert_called_once_with( + {}, mock.ANY, 'INFO', None) + rpc2_driver.notify.assert_called_once_with( + {}, mock.ANY, 'INFO', None) class TestNoOpNotifier(test_utils.BaseTestCase):