I have a class which inherits from kombu.ConsumerProducerMixin
which I would like to test without an actual rabbitmq service running.
class Aggregator(ConsumerProducerMixin):
def __init__(self, broker_url):
exchange_name = 'chargers'
self.status = 0
self.connection = Connection(broker_url)
...
In my test file I did the following:
from unittest.mock import Mock, patch
from aggregator import Aggregator
@patch('kombu.connection.Connection')
def test_on_request(conn_mock):
agg = Aggregator('localhost')
m = Message("", {"action": "start"}, content_type="application/json")
Stepping into the Aggregator.__init__
with the debugger, I see that connection
is still not patched to be a Mock
instance:
(Pdb) self.connection
<Connection: amqp://guest:**@localhost:5672// at 0x7fc8b7f636d8>
(Pdb) Connection
<class 'kombu.connection.Connection'>
My question is how do I properly patch connection such that I don't need rabbitmq to run the tests?