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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -