Skip to content

Commit 7829928

Browse files
test coverage
1 parent 2455043 commit 7829928

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

tests/shared/test_sse.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
from collections.abc import AsyncGenerator, Generator
66
from typing import Any
7+
from unittest.mock import Mock
78

89
import anyio
910
import httpx
@@ -16,6 +17,7 @@
1617
from starlette.responses import Response
1718
from starlette.routing import Mount, Route
1819

20+
import mcp.client.sse
1921
import mcp.types as types
2022
from mcp.client.session import ClientSession
2123
from mcp.client.sse import _extract_session_id_from_endpoint, sse_client
@@ -220,22 +222,19 @@ def test_extract_session_id_from_endpoint(endpoint_url: str, expected: str | Non
220222
async def test_sse_client_on_session_created_not_called_when_no_session_id(
221223
server: None, server_url: str, monkeypatch: pytest.MonkeyPatch
222224
) -> None:
223-
from mcp.client import sse
225+
callback_mock = Mock()
224226

225-
callback_called = False
227+
def mock_extract(url: str) -> None:
228+
return None
226229

227-
def on_session_created(session_id: str) -> None:
228-
nonlocal callback_called
229-
callback_called = True
230-
231-
monkeypatch.setattr(sse, "_extract_session_id_from_endpoint", lambda url: None)
230+
monkeypatch.setattr(mcp.client.sse, "_extract_session_id_from_endpoint", mock_extract)
232231

233-
async with sse_client(server_url + "/sse", on_session_created=on_session_created) as streams:
232+
async with sse_client(server_url + "/sse", on_session_created=callback_mock) as streams:
234233
async with ClientSession(*streams) as session:
235234
result = await session.initialize()
236235
assert isinstance(result, InitializeResult)
237236

238-
assert callback_called is False
237+
callback_mock.assert_not_called()
239238

240239

241240
@pytest.fixture

0 commit comments

Comments
 (0)