Skip to content

Commit 618be64

Browse files
committed
ci(#2484): pragma: no cover on defensive teardown branches
Second CI round got coverage up to 99.97% but the last uncovered lines are defensive cleanup paths that normal teardown does not exercise and that do not warrant a dedicated test each: - `_on_done` callback's "task cancelled" early-return (normal teardown exits the reader/writer cleanly through stream-close, not via explicit cancellation). - `task.cancel()` guard when the task is somehow still pending by the time we reach the finally block (same reason — tasks should be done already). - CancelledError and ClosedResourceError catches in the result collection loop (symmetric with the case above; those arise only if the task was still active when we began teardown). Each line is marked with a terse ``# pragma: no cover`` pointing at the reason, matching the pattern already used elsewhere in this file (e.g. ``except Exception: # pragma: no cover`` on line 143 inside ``_on_done``).
1 parent d546633 commit 618be64

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/mcp/client/stdio.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async def _asyncio_background_tasks(
127127
"""
128128

129129
def _on_done(task: asyncio.Task[None]) -> None:
130-
if task.cancelled():
130+
if task.cancelled(): # pragma: no cover - normal teardown exits reader/writer cleanly
131131
return
132132
exc = task.exception()
133133
if exc is None:
@@ -152,18 +152,18 @@ def _on_done(task: asyncio.Task[None]) -> None:
152152
yield
153153
finally:
154154
for task in tasks:
155-
if not task.done():
155+
if not task.done(): # pragma: no cover - tasks normally exit via stream close
156156
task.cancel()
157157
pending_exc: BaseException | None = None
158158
for task in tasks:
159159
try:
160160
await task
161-
except asyncio.CancelledError:
161+
except asyncio.CancelledError: # pragma: no cover - only if a task was still pending above
162162
pass
163-
except anyio.ClosedResourceError:
163+
except anyio.ClosedResourceError: # pragma: no cover - swallowed by reader/writer already
164164
pass
165165
except BaseException as exc: # noqa: BLE001
166-
if pending_exc is None:
166+
if pending_exc is None: # pragma: no branch
167167
pending_exc = exc
168168
if pending_exc is not None:
169169
raise pending_exc

0 commit comments

Comments
 (0)