python - magicmock called several times but I can't assert called with -
(python 2.6)
i have method:
def send_all(self, messages): message in messages: queue.send(message)
i want assert queue.send()
called each message
queue = magicmock() myobj= myobject(queue) myobj.send_all(test_messages) test_message in test_messages: queue.send.assert_called_once_with(test_message)
each of 55 messages in test_messages
unique. following error:
assertionerror: expected called once. called 55 times.
assert_called_once_with()
tests if mock called once; don't use test 55 different calls.
instead, assert 55 calls made mock.assert_has_calls()
method:
queue.send.assert_has_calls([call(test_message) test_message in test_messages])
this test if sequence of 55 calls present; doesn't limit mock having been called more times.
you test mock.mock_calls
attribute:
assert queue.send.mock_calls == [call(test_message) test_message in test_messages]
this test exactly 55 calls.
Comments
Post a Comment