import time


def wait_for(condition_function, timeout=3):
    """Wait for a condition to be true"""
    start_time = time.time()
    while time.time() < start_time + timeout:
        if condition_function():
            return True
        else:
            time.sleep(0.1)
    raise RuntimeError(
        'Timeout waiting for {}'.format(condition_function.__name__)
    )