From 62eb030c24b96231daa01c2bfbcd6096b843b74e Mon Sep 17 00:00:00 2001 From: JN <56563426+junxit@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:13:26 -0600 Subject: [PATCH 1/2] chore: set pytest-asyncio's fixture loop scope - Set asyncio_default_fixture_loop_scope = "function", the scope pytest-asyncio will default to - With pytest 9.2.0, pytest-asyncio's "option is unset" deprecation warning is raised while pytest configures, and -W error turns it into an internal error before any test runs. This unblocks Dependabot #5 - The suite has no async fixtures, so no fixture changes behavior; 1649 tests pass with -W error on pytest 9.1.1 and 9.2.0 --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index e029c51..24ad846 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ packages = ["src/sx"] testpaths = ["tests"] addopts = "-q" asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" [tool.ruff] line-length = 100 From d326ab6e1b5719b64a33f0dc8bf756a44cbadff6 Mon Sep 17 00:00:00 2001 From: JN <56563426+junxit@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:39:14 -0600 Subject: [PATCH 2/2] test: let dialogs settle before sending them input - The delete test clicked Delete as soon as the dialog became the screen. Its buttons can still be unmounted or 0x0 then, so the click landed on no widget, the dialog never answered, and wait_for_complete() hung until the 120 s guard: 3 of about 7 CI runs, and 3 of 30 local runs under heavy load. A test bug, not an app one: nobody can click a button before it is drawn - _settled() waits until the target widget has a non-empty region that holds still for a pause (and has focus, for the export test's Enter). The delete test also asserts its click landed, so a miss fails at once - Under heavier load than the original repro, 45 of 45 runs pass Closes #20 --- tests/test_tui_workers.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/tests/test_tui_workers.py b/tests/test_tui_workers.py index cdfc41c..24057ce 100644 --- a/tests/test_tui_workers.py +++ b/tests/test_tui_workers.py @@ -166,6 +166,38 @@ async def _gated(pilot, adapter: _Gated) -> None: await _until(pilot, adapter.entered.is_set) +async def _settled(pilot, screen_type: type, selector: str, *, focused: bool = False) -> None: + """Wait until a ``screen_type`` dialog is up and ``selector`` in it is laid out. + + A dialog becomes ``app.screen`` before its widgets are mounted, and they + are mounted before they are laid out. Input sent in between goes nowhere: + a click aimed at a button whose region is still empty lands on no widget, + so the dialog never answers and the worker waiting on it never finishes. + Under load that hung the suite (#20). The region must also hold still for + one pause, since the delete dialog fits its preview to the screen after + its first refresh. + + Args: + pilot: The app's pilot. + screen_type: The dialog expected on top. + selector: The widget input will be sent to. + focused: Whether that widget must also have focus, for key presses. + """ + app = pilot.app + await _until(pilot, lambda: isinstance(app.screen, screen_type)) + last = None + for _ in range(100): + nodes = app.screen.query(selector) + node = nodes.first() if nodes else None + region = node.region if node is not None else None + ready = region is not None and region.area > 0 and region == last + if ready and (not focused or app.focused is node): + return + last = region + await pilot.pause() + raise AssertionError(f"{selector} on {screen_type.__name__} never settled") + + @pytest.mark.asyncio async def test_a_superseded_load_never_reaches_the_pane(tmp_path): """The session opened last owns the pane and ``t``, whichever parse ends last (T9).""" @@ -207,7 +239,7 @@ async def test_opening_a_session_does_not_cancel_an_export(tmp_path, monkeypatch await app.open_session(sessions["fast"]).wait() finally: adapter.gate.set() - await _until(pilot, lambda: isinstance(app.screen, BranchModeScreen)) + await _settled(pilot, BranchModeScreen, "#modes", focused=True) await pilot.press("enter") await app.workers.wait_for_complete() @@ -231,9 +263,9 @@ async def test_opening_a_session_does_not_cancel_a_delete(tmp_path, monkeypatch) await app.open_session(sessions["fast"]).wait() finally: adapter.gate.set() - await _until(pilot, lambda: isinstance(app.screen, ConfirmDeleteScreen)) + await _settled(pilot, ConfirmDeleteScreen, "#confirm") - await pilot.click("#confirm") + assert await pilot.click("#confirm"), "the click must land on Delete" await app.workers.wait_for_complete() await pilot.pause() assert not sessions["slow"].primary_path.exists()