diff --git a/tests/tui_gateway/test_goal_command.py b/tests/tui_gateway/test_goal_command.py index 050b36bc877..d06f5b8fbbd 100644 --- a/tests/tui_gateway/test_goal_command.py +++ b/tests/tui_gateway/test_goal_command.py @@ -44,11 +44,17 @@ def server(hermes_home): ): mod = importlib.import_module("tui_gateway.server") yield mod + # Reset module-level session state without re-importing. importlib.reload + # would re-register the module's atexit hooks (ThreadPoolExecutor + # shutdown, _shutdown_sessions); the duplicates race the stderr + # buffer at interpreter shutdown and surface as Fatal Python error: + # _enter_buffered_busy. Clearing the per-session dicts gives the + # next test a clean slate; _methods is NOT cleared because it's + # populated at module import time and re-registration only happens + # via reload (which we don't do). mod._sessions.clear() mod._pending.clear() mod._answers.clear() - mod._methods.clear() - importlib.reload(mod) @pytest.fixture() diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.py index a26a360a24d..f2f68efbf55 100644 --- a/tests/tui_gateway/test_protocol.py +++ b/tests/tui_gateway/test_protocol.py @@ -30,11 +30,17 @@ def server(): import importlib mod = importlib.import_module("tui_gateway.server") yield mod + # Reset module-level session state without re-importing. importlib.reload + # would re-register the module's atexit hooks (ThreadPoolExecutor + # shutdown, _shutdown_sessions); the duplicates race the stderr + # buffer at interpreter shutdown and surface as Fatal Python error: + # _enter_buffered_busy. Clearing the per-session dicts gives the + # next test a clean slate; _methods is NOT cleared because it's + # populated at module import time and re-registration only happens + # via reload (which we don't do). mod._sessions.clear() mod._pending.clear() mod._answers.clear() - mod._methods.clear() - importlib.reload(mod) @pytest.fixture() diff --git a/tests/tui_gateway/test_review_summary_callback.py b/tests/tui_gateway/test_review_summary_callback.py index 9fc7f54ddc6..f2d97f1a487 100644 --- a/tests/tui_gateway/test_review_summary_callback.py +++ b/tests/tui_gateway/test_review_summary_callback.py @@ -34,11 +34,17 @@ def server(): mod = importlib.import_module("tui_gateway.server") yield mod + # Reset module-level session state without re-importing. importlib.reload + # would re-register the module's atexit hooks (ThreadPoolExecutor + # shutdown, _shutdown_sessions); the duplicates race the stderr + # buffer at interpreter shutdown and surface as Fatal Python error: + # _enter_buffered_busy. Clearing the per-session dicts gives the + # next test a clean slate; _methods is NOT cleared because it's + # populated at module import time and re-registration only happens + # via reload (which we don't do). mod._sessions.clear() mod._pending.clear() mod._answers.clear() - mod._methods.clear() - importlib.reload(mod) def test_init_session_attaches_background_review_callback(server, monkeypatch):