test: standardize async tests on pytest-asyncio auto mode (#338)
* chore: add pytest-asyncio in auto mode * test: migrate channel and stream tests to native async Convert run_async() wrapper tests to plain 'async def test_*' under pytest-asyncio auto mode. collect_events() in stream_v3_fakes becomes a coroutine awaited at every call site. * test: migrate command and model/middleware tests to native async Convert run_async() wrappers (import, alias, and fixture forms) to plain 'async def test_*'. Multi-call tests merge onto one loop as sequential awaits; none asserted on loop identity. * test: migrate TUI, notifier, gateway, and session tests to native async TUI/notifier/gateway files convert run_async wrappers to plain async tests. test_sessions.py's unittest.TestCase classes move to unittest.IsolatedAsyncioTestCase (pytest-asyncio does not await async methods on plain TestCase; converting blindly would have made ~70 tests silently vacuous). Its setUpClass keeps a one-shot asyncio.run() since IsolatedAsyncioTestCase has no async class-level hook. TestLoadingWidget in test_tui_widgets.py drops its TestCase base for the same reason. * test: replace direct asyncio.run() calls with native async tests Convert tests that called asyncio.run() (directly or via a local _run helper) to plain 'async def test_*'; delete the local helpers. * test: drop undeclared anyio markers and delete run_async helper The @pytest.mark.anyio tests relied on anyio being a transitive dep of httpx; auto-mode pytest-asyncio collects them natively. run_async() and its fixture are unreferenced after the migration, so remove them — pytest-asyncio's per-test loop teardown covers the pending-task cancellation the helper existed for (verified: full suite runs with no 'Event loop is closed' errors or destroyed-task warnings).
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
from tests.conftest import run_async as _run
|
||||
from tests.fakes import FakeGraphGateway, FakeThreadStore
|
||||
|
||||
|
||||
@@ -21,17 +20,17 @@ def _ctx(thread_id="current", thread_store=None):
|
||||
|
||||
|
||||
class TestDeleteCommand:
|
||||
def test_refuses_to_delete_current(self):
|
||||
async def test_refuses_to_delete_current(self):
|
||||
from EvoScientist.commands.implementation.session import DeleteCommand
|
||||
|
||||
thread_store = FakeThreadStore(resolved_thread_id="current", deleted=True)
|
||||
ctx, ui = _ctx(thread_id="current", thread_store=thread_store)
|
||||
_run(DeleteCommand().execute(ctx, ["current"]))
|
||||
await DeleteCommand().execute(ctx, ["current"])
|
||||
assert ("delete_thread", "current") not in thread_store.calls
|
||||
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
||||
assert any("Cannot delete the current session" in m for m in msgs)
|
||||
|
||||
def test_happy_path_success(self):
|
||||
async def test_happy_path_success(self):
|
||||
from EvoScientist.commands.implementation.session import DeleteCommand
|
||||
|
||||
ctx, ui = _ctx(
|
||||
@@ -41,45 +40,45 @@ class TestDeleteCommand:
|
||||
deleted=True,
|
||||
),
|
||||
)
|
||||
_run(DeleteCommand().execute(ctx, ["other-thread"]))
|
||||
await DeleteCommand().execute(ctx, ["other-thread"])
|
||||
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
||||
assert any("Deleted session other-thread" in m for m in msgs)
|
||||
|
||||
def test_not_found(self):
|
||||
async def test_not_found(self):
|
||||
from EvoScientist.commands.implementation.session import DeleteCommand
|
||||
|
||||
ctx, ui = _ctx()
|
||||
_run(DeleteCommand().execute(ctx, ["missing"]))
|
||||
await DeleteCommand().execute(ctx, ["missing"])
|
||||
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
||||
assert any("not found" in m for m in msgs)
|
||||
|
||||
def test_ambiguous_prefix(self):
|
||||
async def test_ambiguous_prefix(self):
|
||||
from EvoScientist.commands.implementation.session import DeleteCommand
|
||||
|
||||
ctx, ui = _ctx(thread_store=FakeThreadStore(matches=["abc-one", "abc-two"]))
|
||||
_run(DeleteCommand().execute(ctx, ["abc"]))
|
||||
await DeleteCommand().execute(ctx, ["abc"])
|
||||
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
||||
assert any("Ambiguous" in m for m in msgs)
|
||||
|
||||
def test_prefix_resolves_to_unique_match(self):
|
||||
async def test_prefix_resolves_to_unique_match(self):
|
||||
from EvoScientist.commands.implementation.session import DeleteCommand
|
||||
|
||||
ctx, ui = _ctx(
|
||||
thread_store=FakeThreadStore(resolved_thread_id="abc-one", deleted=True)
|
||||
)
|
||||
_run(DeleteCommand().execute(ctx, ["abc"]))
|
||||
await DeleteCommand().execute(ctx, ["abc"])
|
||||
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
||||
assert any("Deleted session abc-one" in m for m in msgs)
|
||||
|
||||
def test_no_arg_empty_sessions_prints_notice(self):
|
||||
async def test_no_arg_empty_sessions_prints_notice(self):
|
||||
from EvoScientist.commands.implementation.session import DeleteCommand
|
||||
|
||||
ctx, ui = _ctx()
|
||||
_run(DeleteCommand().execute(ctx, []))
|
||||
await DeleteCommand().execute(ctx, [])
|
||||
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
||||
assert any("No sessions to delete" in m for m in msgs)
|
||||
|
||||
def test_no_arg_calls_picker_returns_none(self):
|
||||
async def test_no_arg_calls_picker_returns_none(self):
|
||||
"""When no arg and picker returns None, nothing is deleted."""
|
||||
from EvoScientist.commands.implementation.session import DeleteCommand
|
||||
|
||||
@@ -96,5 +95,5 @@ class TestDeleteCommand:
|
||||
]
|
||||
store = FakeThreadStore(threads=threads)
|
||||
ctx.graph_gateway = FakeGraphGateway(thread_store=store)
|
||||
_run(DeleteCommand().execute(ctx, []))
|
||||
await DeleteCommand().execute(ctx, [])
|
||||
ui.wait_for_thread_pick.assert_awaited_once()
|
||||
|
||||
Reference in New Issue
Block a user