title: Python mocking, return different value every call
body: <p>I am testing a method, <code>geodata_collect._request_loc_data()</code>, and within that method I call another method, <code>geodata_collect.utils.loadJSON(...)</code> which I need to mock in order to unit-test the first mentioned method. </p>
  
  <p>My problem is that I need <code>geodata_collect.utils.loadJSON(...)</code> to return a different value the third time it is called from within <code>geodata_collect._request_loc_data()</code>.</p>
  
  <p>I have been exploring <code>MagicMock</code> and <code>side_effect</code> in order to do this.</p>
  
  <pre><code>mock = MagicMock()
  mock.side_effect = [self._create_request_dict(next_page_token=True),
      self._create_request_dict(next_page_token=True), self._create_request_dict()]
  
  with patch('geodata_collect.utils.loadJSON',return_value=mock):
      geodata_collect._request_loc_data()
  </code></pre>
  
  <p>However, when <code>geodata_collect.utils.loadJSON(...)</code> is called from within <code>geodata_collect._request_loc_data()</code> the MagicMock class is returned, instead of the actual value.</p>
  
  <pre><code>&lt;MagicMock id='140642209064888'&gt;
  </code></pre>
  
  <p>What should be returned:</p>
  
  <pre><code>{'status': 'OK', 'next_page_token': 'Next Page EXISTS!!', 'result': [1, 2, 3, 4, 5]}
  {'status': 'OK', 'next_page_token': 'Next Page EXISTS!!', 'result': [1, 2, 3, 4, 5]}
  {'status': 'OK', 'result': [1, 2, 3, 4, 5]}
  </code></pre>