Skip to content

Commit 609d118

Browse files
committed
test: satisfy streamable http coverage checks
1 parent f230376 commit 609d118

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/mcp/client/session_group.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ def __init__(
147147
self._session_exit_stacks = {}
148148
self._component_name_hook = component_name_hook
149149

150-
async def __aenter__(self) -> Self: # pragma: no cover
150+
async def __aenter__(self) -> Self:
151151
# Enter the exit stack only if we created it ourselves
152-
if self._owns_exit_stack:
152+
if self._owns_exit_stack: # pragma: no branch
153153
await self._exit_stack.__aenter__()
154154
return self
155155

@@ -158,22 +158,22 @@ async def __aexit__(
158158
_exc_type: type[BaseException] | None,
159159
_exc_val: BaseException | None,
160160
_exc_tb: TracebackType | None,
161-
) -> bool | None: # pragma: no cover
161+
) -> bool | None:
162162
"""Closes session exit stacks and main exit stack upon completion."""
163163

164164
# Only close the main exit stack if we created it
165-
if self._owns_exit_stack:
165+
if self._owns_exit_stack: # pragma: no branch
166166
await self._exit_stack.aclose()
167167

168168
# Concurrently close session stacks.
169169
async with anyio.create_task_group() as tg:
170170
for exit_stack in self._session_exit_stacks.values():
171-
tg.start_soon(exit_stack.aclose)
171+
tg.start_soon(exit_stack.aclose) # pragma: no cover
172172

173173
@property
174174
def sessions(self) -> list[mcp.ClientSession]:
175175
"""Returns the list of sessions being managed."""
176-
return list(self._sessions.keys()) # pragma: no cover
176+
return list(self._sessions.keys())
177177

178178
@property
179179
def prompts(self) -> dict[str, types.Prompt]:
@@ -323,7 +323,7 @@ async def _establish_session(
323323
await self._exit_stack.enter_async_context(session_stack)
324324

325325
return result.server_info, session
326-
except Exception: # pragma: no cover
326+
except Exception:
327327
# If anything during this setup fails, ensure the session-specific
328328
# stack is closed.
329329
await session_stack.aclose()

tests/client/test_notification_response.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ async def raise_connect_error(request: httpx.Request) -> httpx.Response:
162162
async with httpx.AsyncClient(transport=httpx.MockTransport(raise_connect_error)) as client:
163163
async with streamable_http_client("http://localhost/mcp", http_client=client) as (read_stream, write_stream):
164164
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
165-
with pytest.raises(MCPError, match="Transport error: All connection attempts failed"):
165+
with pytest.raises(
166+
MCPError, match="Transport error: All connection attempts failed"
167+
): # pragma: no branch
166168
await session.initialize()
167169

168170

tests/client/test_session_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def mock_client_factory(
402402
group = ClientSessionGroup()
403403
async with group:
404404
with mock.patch("mcp.client.session_group.create_mcp_http_client", side_effect=mock_client_factory):
405-
with pytest.raises(MCPError, match="Transport error: All connection attempts failed"):
405+
with pytest.raises(MCPError, match="Transport error: All connection attempts failed"): # pragma: no branch
406406
await group.connect_to_server(StreamableHttpParameters(url="http://localhost:3001/mcp/"))
407407

408408
assert group.sessions == []

0 commit comments

Comments
 (0)