test a function called twice in python
@patch('call_me')def test_func(self,mock_call_me): self.assertEqual(func(),None) self.assertEqual(mock_call_me.call_count, 2)
You can even check parameters passed to each call:
from mock import patch, call@patch('call_me')def test_func(self, mock_call_me): self.val="abc" self.assertEqual(func(),None) mock_call_me.assert_has_calls([call(self.val), call(self.val)])
I know that if you use flexmock then you can just write it this way:
flexmock(call_me).should_receive('abc').once()
flexmock(call_me).should_receive('abc').twice()