Skip to content

Commit 101fddd

Browse files
committed
fix: use lax no cover for resumption test inter-phase code
Move assertions inside ClientSession blocks where possible. Lines between the two connection phases (clearing state, setting up headers) are not tracked by coverage on Python 3.11 due to a sys.settrace interaction with cancel scopes — mark them with pragma: lax no cover.
1 parent a508913 commit 101fddd

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

tests/shared/test_streamable_http.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,20 +1302,21 @@ async def run_tool():
13021302
# Kill the client session while tool is waiting on lock
13031303
tg.cancel_scope.cancel()
13041304

1305-
# Verify we received exactly one notification
1306-
assert len(captured_notifications) == 1
1307-
assert isinstance(captured_notifications[0], types.LoggingMessageNotification)
1308-
assert captured_notifications[0].params.data == "First notification before lock"
1309-
1310-
# Clear notifications for the second phase
1311-
captured_notifications = []
1312-
1313-
# Now resume the session with the same mcp-session-id and protocol version
1314-
headers: dict[str, Any] = {}
1315-
assert captured_session_id is not None
1316-
headers[MCP_SESSION_ID_HEADER] = captured_session_id
1317-
assert captured_protocol_version is not None
1318-
headers[MCP_PROTOCOL_VERSION_HEADER] = captured_protocol_version
1305+
# Verify we received exactly one notification (inside ClientSession
1306+
# so coverage tracks these on Python 3.11, see PR #1897 for details)
1307+
assert len(captured_notifications) == 1
1308+
assert isinstance(captured_notifications[0], types.LoggingMessageNotification)
1309+
assert captured_notifications[0].params.data == "First notification before lock"
1310+
1311+
# Clear notifications and set up headers for phase 2 (between connections,
1312+
# not tracked by coverage on Python 3.11 due to cancel scope + sys.settrace bug)
1313+
captured_notifications = [] # pragma: lax no cover
1314+
assert captured_session_id is not None # pragma: lax no cover
1315+
assert captured_protocol_version is not None # pragma: lax no cover
1316+
headers: dict[str, Any] = { # pragma: lax no cover
1317+
MCP_SESSION_ID_HEADER: captured_session_id,
1318+
MCP_PROTOCOL_VERSION_HEADER: captured_protocol_version,
1319+
}
13191320

13201321
async with create_mcp_http_client(headers=headers) as httpx_client:
13211322
async with streamable_http_client(f"{server_url}/mcp", http_client=httpx_client) as (
@@ -1345,9 +1346,8 @@ async def run_tool():
13451346

13461347
# We should have received the remaining notifications
13471348
assert len(captured_notifications) == 1
1348-
1349-
assert isinstance(captured_notifications[0], types.LoggingMessageNotification)
1350-
assert captured_notifications[0].params.data == "Second notification after lock"
1349+
assert isinstance(captured_notifications[0], types.LoggingMessageNotification)
1350+
assert captured_notifications[0].params.data == "Second notification after lock"
13511351

13521352

13531353
@pytest.mark.anyio

0 commit comments

Comments
 (0)