Skip to content

Commit 31e49dd

Browse files
committed
fix: coverage pragmas for platform-dependent async coverage gaps
- test_multi_tenancy_e2e.py: use `pragma: lax no cover` on `tg.cancel_scope.cancel()` lines — covered locally but missed on some CI matrix entries due to cancellation unwinding differences - test_multi_tenancy_oauth_e2e.py: use `pragma: no branch` on nested `async with ClientSession` — coverage.py misreports the ->exit arc for nested async with on Python 3.11+
1 parent 491112a commit 31e49dd

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

tests/server/mcpserver/test_multi_tenancy_e2e.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ async def run_server() -> None:
102102
assert len(tools.tools) == 1
103103
assert tools.tools[0].name == "compute"
104104

105-
tg.cancel_scope.cancel()
105+
tg.cancel_scope.cancel() # pragma: lax no cover
106106

107107

108108
async def test_tenant_b_sees_only_own_tools():
@@ -133,7 +133,7 @@ async def run_server() -> None:
133133
assert len(tools.tools) == 1
134134
assert tools.tools[0].name == "compute"
135135

136-
tg.cancel_scope.cancel()
136+
tg.cancel_scope.cancel() # pragma: lax no cover
137137

138138

139139
async def test_global_scope_sees_nothing_when_all_tenant_scoped():
@@ -164,7 +164,7 @@ async def test_global_scope_sees_nothing_when_all_tenant_scoped():
164164
prompts = await session.list_prompts()
165165
assert len(prompts.prompts) == 0
166166

167-
tg.cancel_scope.cancel()
167+
tg.cancel_scope.cancel() # pragma: lax no cover
168168

169169

170170
async def test_tenant_tool_returns_correct_result():
@@ -195,7 +195,7 @@ async def run_server() -> None:
195195
texts = [c.text for c in result.content if isinstance(c, TextContent)]
196196
assert any("tenant-a:42" in t for t in texts)
197197

198-
tg.cancel_scope.cancel()
198+
tg.cancel_scope.cancel() # pragma: lax no cover
199199

200200

201201
async def test_tenant_resource_isolation():
@@ -227,7 +227,7 @@ async def run_server(tid: str = tenant) -> None:
227227
assert len(resources.resources) == 1
228228
assert resources.resources[0].name == expected_name
229229

230-
tg.cancel_scope.cancel()
230+
tg.cancel_scope.cancel() # pragma: lax no cover
231231

232232

233233
async def test_tenant_prompt_isolation():
@@ -263,7 +263,7 @@ async def run_server(tid: str = tenant) -> None:
263263
text = result.messages[0].content.text # type: ignore[union-attr]
264264
assert tenant in text
265265

266-
tg.cancel_scope.cancel()
266+
tg.cancel_scope.cancel() # pragma: lax no cover
267267

268268

269269
async def test_context_tenant_id_available_in_tool():
@@ -301,7 +301,7 @@ async def run_server() -> None:
301301
await session.initialize()
302302
await session.call_tool("check_tenant", {})
303303

304-
tg.cancel_scope.cancel()
304+
tg.cancel_scope.cancel() # pragma: lax no cover
305305

306306
assert captured_tenant == ["my-tenant"]
307307

tests/server/mcpserver/test_multi_tenancy_oauth_e2e.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ async def test_alpha_sees_only_own_tools(starlette_app: Starlette):
297297
url="http://localhost/mcp",
298298
http_client=http_client,
299299
) as (read_stream, write_stream):
300-
async with ClientSession(read_stream, write_stream) as session:
300+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
301301
await session.initialize()
302302
# List tools — should only see alpha's tools
303303
tools = await session.list_tools()
@@ -321,7 +321,7 @@ async def test_beta_sees_only_own_tools(starlette_app: Starlette):
321321
url="http://localhost/mcp",
322322
http_client=http_client,
323323
) as (read_stream, write_stream):
324-
async with ClientSession(read_stream, write_stream) as session:
324+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
325325
await session.initialize()
326326
tools = await session.list_tools()
327327
tool_names = sorted(t.name for t in tools.tools)
@@ -345,7 +345,7 @@ async def test_alpha_can_call_own_tool(starlette_app: Starlette):
345345
url="http://localhost/mcp",
346346
http_client=http_client,
347347
) as (read_stream, write_stream):
348-
async with ClientSession(read_stream, write_stream) as session:
348+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
349349
await session.initialize()
350350
result = await session.call_tool("query", {"sql": "SELECT 1"})
351351
texts = [c.text for c in result.content if isinstance(c, TextContent)]
@@ -375,7 +375,7 @@ async def test_whoami_returns_correct_tenant(starlette_app: Starlette):
375375
url="http://localhost/mcp",
376376
http_client=http_client,
377377
) as (read_stream, write_stream):
378-
async with ClientSession(read_stream, write_stream) as session:
378+
async with ClientSession(read_stream, write_stream) as session: # pragma: no branch
379379
await session.initialize()
380380
result = await session.call_tool("whoami", {})
381381
texts = [c.text for c in result.content if isinstance(c, TextContent)]

0 commit comments

Comments
 (0)