title: Python mock multiple return values
body: <p>I am using pythons mock.patch and would like to change the return value for each call.
  Here is the caveat:
  the function being patched has no inputs, so I can not change the return value based on the input.</p>
  
  <p>Here is my code for reference.</p>
  
  <pre><code>def get_boolean_response():
      response = io.prompt('y/n').lower()
      while response not in ('y', 'n', 'yes', 'no'):
          io.echo('Not a valid input. Try again'])
          response = io.prompt('y/n').lower()
  
      return response in ('y', 'yes')
  </code></pre>
  
  <p>My Test code:</p>
  
  <pre><code>@mock.patch('io')
  def test_get_boolean_response(self, mock_io):
      #setup
      mock_io.prompt.return_value = ['x','y']
      result = operations.get_boolean_response()
  
      #test
      self.assertTrue(result)
      self.assertEqual(mock_io.prompt.call_count, 2)
  </code></pre>
  
  <p><code>io.prompt</code> is just a platform independent (python 2 and 3) version of "input". So ultimately I am trying to mock out the users input. I have tried using a list for the return value, but that doesn't seam to work.</p>
  
  <p>You can see that if the return value is something invalid, I will just get an infinite loop here. So I need a way to eventually change the return value, so that my test actually finishes.</p>
  
  <p>(another possible way to answer this question could be to explain how I could mimic user input in a unit-test)</p>
  
  <hr>
  
  <p>Not a dup of <a href="https://stackoverflow.com/questions/7665682/python-mock-object-with-method-called-multiple-times">this question</a> mainly because I do not have the ability to vary the inputs.</p>
  
  <p>One of the comments of the Answer on <a href="https://stackoverflow.com/questions/21927057/mock-patch-os-path-exists-with-multiple-return-values">this question</a> is along the same lines, but no answer/comment has been provided.</p>