(condition, msg=None, timeout=TIMEOUT, sleep=0.05)
| 157 | |
| 158 | |
| 159 | def wait_for_condition(condition, msg=None, timeout=TIMEOUT, sleep=0.05): |
| 160 | curtime = time.time() |
| 161 | while True: |
| 162 | if condition(): |
| 163 | break |
| 164 | if time.time() - curtime > timeout: |
| 165 | error_msg = "Condition not reached in %s seconds" % (timeout,) |
| 166 | if msg is not None: |
| 167 | error_msg += "\n" |
| 168 | if callable(msg): |
| 169 | error_msg += msg() |
| 170 | else: |
| 171 | error_msg += str(msg) |
| 172 | |
| 173 | raise TimeoutError(error_msg) |
| 174 | time.sleep(sleep) |
| 175 | |
| 176 | |
| 177 | class IgnoreFailureError(RuntimeError): |
no test coverage detected