title: Python Mock Multiple Calls with Different Results
body: <p>I want to be able to have multiple calls to a particular attribute function return a different result for each successive call.</p>
  
  <p>In the below example, I would like increment to return 5 on its first call and then 10 on its second call.</p>
  
  <p>Ex:</p>
  
  <pre><code>import mock
  
  class A:
      def __init__(self):
          self.size = 0
      def increment(self, amount):
          self.size += amount
          return amount
  
  @mock.patch("A.increment")
  def test_method(self, mock_increment):
      def diff_inc(*args):
          def next_inc(*args):
              #I don't know what belongs in __some_obj__
              some_obj.side_effect = next_inc
              return 10
          return 5
  
      mock_increment.side_effect = diff_inc
  </code></pre>
  
  <p>The below page has almost everything that I need except that it assumes that the caller would be an object named "mock", but this can't be assumed.</p>
  
  <p><a href="http://mock.readthedocs.org/en/latest/examples.html#multiple-calls-with-different-effects" rel="noreferrer">http://mock.readthedocs.org/en/latest/examples.html#multiple-calls-with-different-effects</a></p>