From c581a5bd0ff76a91f23446de5d537305dadf3854 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Mon, 16 Nov 2026 22:55:06 -0500 Subject: [PATCH] Wait for a window title to be written before replacing it in a test test_instance_titles_do_not_cross_between_concurrent_select_menus sets the title "B" while the second menu is running and then, once the first menu has finished, "B active". A title set during a prompt is written by a callback on the prompt's event loop, and a title set before that callback runs replaces it. Nothing made the second menu's loop run before "B active" was set, so under load "B" was never written and the test failed. Wait for the second menu's loop to get past the callback before going on. --- tests/test_window_title.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_window_title.py b/tests/test_window_title.py index 1b0d598fc..08ee318d9 100644 --- a/tests/test_window_title.py +++ b/tests/test_window_title.py @@ -210,12 +210,12 @@ def after_render(_sender): def test_instance_titles_do_not_cross_between_concurrent_select_menus(monkeypatch): streams = [TtyStream(), TtyStream()] rendered = [threading.Event(), threading.Event()] - menus = [] + menus = {} run = Application.run def run_menu(menu, *args, **kwargs): index = next(index for index, stream in enumerate(streams) if menu.output.stdout is stream) - menus.append(menu) + menus[index] = menu menu.after_render += lambda _sender: rendered[index].set() return run(menu, *args, set_exception_handler=False, **kwargs) @@ -231,12 +231,19 @@ def run_menu(menu, *args, **kwargs): assert all(event.wait(timeout=5) for event in rendered) apps[0].set_window_title("A") apps[1].set_window_title("B") + + # The second menu's loop writes "B" in a callback. Wait for that loop to get past it, since a title + # set before the callback runs replaces "B" instead of following it. + title_written = threading.Event() + menus[1].loop.call_soon_threadsafe(title_written.set) + assert title_written.wait(timeout=5) + inputs[0].send_text("\r") assert results[0].result(timeout=5) == "selected" apps[0].set_window_title("A finished") apps[1].set_window_title("B active") finally: - for menu in menus: + for menu in menus.values(): loop = menu.loop if loop is not None and loop.is_running(): loop.call_soon_threadsafe(lambda menu=menu: menu.exit(result="selected"))