title: override python function-local variable in unittest
body: <p>I have a method in python (2.7) that does foo, and gives up after 5 minutes if foo didn't work.</p>
  
  <pre><code>def keep_trying(self):
      timeout = 300  #empirically derived, appropriate timeout
      end_time = time.time() + timeout
      while (time.time() &lt; end_time):
          result = self.foo()
          if (result == 'success'):
              break
          time.sleep(2)
      else:
          raise MyException('useful msg here')
  </code></pre>
  
  <p>I know some possible results from foo(), so I am using mock to fake those return values.  The problem is, I don't want the test to run 5 minutes before it gets to see the exception.</p>
  
  <p>Is there a way to override that local value of timeout?  I'd like that to be just a few seconds so that I can see the loop try a couple times, then give up and raise.</p>
  
  <p>The following does not work:</p>
  
  <pre><code>@patch.object(myClass.keep_trying, 'timeout')
  @patch.object(myClass, 'foo')
  def test_keep_trying(self, mock_foo, mock_timeout):
      mock_foo.return_value = 'failed'
      mock_timeout.return_value = 10 # raises AttributeError
      mock_timeout = 10 # raises AttributeError
      ...
  </code></pre>