test: address 3.11/3.14 coverage instrumentation quirks

3.14: nested async-with arc misreporting on three create_task_group lines
(the documented AGENTS.md case) — pragma: no branch.

3.11: lines after async-CM exit with pytest.raises mis-traced in one test —
moved the asserts inside the context manager.
This commit is contained in:
Max Isbey
2026-04-16 17:29:41 +00:00
parent cffb527956
commit 0a8f0f4607
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -208,8 +208,8 @@ async def test_direct_send_raw_request_wraps_non_mcperror_exception_as_internal_
async with running_pair(direct_pair, server_on_request=on_request) as (client, *_):
with anyio.fail_after(5), pytest.raises(MCPError) as exc:
await client.send_raw_request("tools/list", {})
assert exc.value.error.code == INTERNAL_ERROR
assert isinstance(exc.value.__cause__, ValueError)
assert exc.value.error.code == INTERNAL_ERROR
assert isinstance(exc.value.__cause__, ValueError)
@pytest.mark.anyio
+3 -3
View File
@@ -56,7 +56,7 @@ async def test_concurrent_send_requests_correlate_by_id_when_responses_arrive_ou
results[method] = await client.send_request(method, None)
with anyio.fail_after(5):
async with anyio.create_task_group() as tg:
async with anyio.create_task_group() as tg: # pragma: no branch
tg.start_soon(call, "first")
await anyio.sleep(0)
tg.start_soon(call, "second")
@@ -99,7 +99,7 @@ async def test_peer_cancel_interrupt_mode_sets_cancel_requested_and_sends_no_res
async with running_pair(jsonrpc_pair, server_on_request=server_on_request) as (client, *_):
with anyio.fail_after(5):
async with anyio.create_task_group() as tg:
async with anyio.create_task_group() as tg: # pragma: no branch
async def call_then_record() -> None:
with pytest.raises(MCPError): # we'll cancel via tg below
@@ -137,7 +137,7 @@ async def test_peer_cancel_signal_mode_sets_event_but_handler_runs_to_completion
result_box: list[dict[str, Any]] = []
async with running_pair(factory, server_on_request=server_on_request) as (client, *_):
with anyio.fail_after(5):
async with anyio.create_task_group() as tg:
async with anyio.create_task_group() as tg: # pragma: no branch
async def call() -> None:
result_box.append(await client.send_request("slow", None))