I have a method in python (2.7) that does foo, and gives up after 5 minutes if foo didn\'t work.
def keep_trying(self): timeout = 300 #empirically derived,
You can't mock a function's local variable. To make your code easier to test, change it to, e.g:
def keep_trying(self, timeout=300): end_time = time.time() + timeout # etc, as above
so it becomes trivial for tests to run it with a shorter timeout!