I'm using Python 3.8. I have a class with a member field ...
class AbcServiceBus:
def __init__(self, ...):
...
self._service_bus = AzureServiceBus()
def send_insert_notification(self, record_id):
message_json = {'ids': [record_id]}
self._service_bus.send_topic_message(
namespace_name=self._namespace,
topic_name=self._topic_name,
message_json=message_json
)
return True
I would like to mock the "send_topic_message" method of the member field. I tried the below
from unittest import mock
...
sb = AbcServiceBus(device)
with mock.patch('common.azure_service_bus.AzureServiceBus.send_topic_message') as send_topic_message_mock:
sb.send_insert_notification(record_id)
send_topic_message_mock.assert_called_with(
sb._namespace,
sb._topic_name,
{'ids': [record_id]}
)
but this continues to call the real method of the class, as opposed to the mock I have set up. What's the proper way to mock the method of the member field?