From c17d7614e1055bd8ec876aa4683c445ce239c09b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 11 May 2024 08:33:47 +0530 Subject: [PATCH] Allow showing a more useful error message when wait_till fails --- kitty_tests/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kitty_tests/__init__.py b/kitty_tests/__init__.py index ca2d89216..a6f39cde8 100644 --- a/kitty_tests/__init__.py +++ b/kitty_tests/__init__.py @@ -366,12 +366,15 @@ class PTY: parse_bytes(self.screen, data) return bytes_read - def wait_till(self, q, timeout=10): + def wait_till(self, q, timeout=10, timeout_msg=None): end_time = time.monotonic() + timeout while not q() and time.monotonic() <= end_time: self.process_input_from_child(timeout=end_time - time.monotonic()) if not q(): - raise TimeoutError(f'The condition was not met. Screen contents: \n {repr(self.screen_contents())}') + msg = 'The condition was not met' + if timeout_msg is not None: + msg = timeout_msg() + raise TimeoutError(f'Timed out: {msg}. Screen contents: \n {repr(self.screen_contents())}') def wait_till_child_exits(self, timeout=30 if BaseTest.is_ci else 10, require_exit_code=None): end_time = time.monotonic() + timeout