diff --git a/tests/cli/test_cli_status_bar.py b/tests/cli/test_cli_status_bar.py index 3edc1e94c80..1899f0dd78e 100644 --- a/tests/cli/test_cli_status_bar.py +++ b/tests/cli/test_cli_status_bar.py @@ -400,13 +400,20 @@ class TestCLIStatusBar: cli_obj = _make_cli() cli_obj._spinner_text = "running tool" - # <60s path - cli_obj._tool_start_time = time.monotonic() - 9.2 - short = cli_obj._render_spinner_text() + # Pin the clock: time.monotonic()'s epoch is arbitrary (often near + # boot), so deriving _tool_start_time from the real monotonic clock + # made the test fail on hosts where monotonic() < 65.2 — the start + # time went negative, the (t0 > 0) guard in _render_spinner_text + # dropped the "(elapsed)" suffix entirely, and the split below hit an + # IndexError. A fixed clock keeps both elapsed paths deterministic. + with patch.object(cli_mod.time, "monotonic", return_value=1000.0): + # <60s path + cli_obj._tool_start_time = 1000.0 - 9.2 + short = cli_obj._render_spinner_text() - # >=60s path - cli_obj._tool_start_time = time.monotonic() - 65.2 - long = cli_obj._render_spinner_text() + # >=60s path + cli_obj._tool_start_time = 1000.0 - 65.2 + long = cli_obj._render_spinner_text() short_elapsed = short.split("(", 1)[1].rstrip(")") long_elapsed = long.split("(", 1)[1].rstrip(")")