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!