Skip to content

Commit 483553e

Browse files
committed
Ignore coverage on test lines that are designed not to be executed
1 parent 2dabcc8 commit 483553e

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

tests/client/test_session_tasks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def test_client_get_task_not_found():
9292
# Try to get non-existent task
9393
try:
9494
await client_session.get_task("non-existent")
95-
assert False, "Should have raised McpError"
95+
assert False, "Should have raised McpError" # pragma: no cover
9696
except Exception as e:
9797
assert "Task not found" in str(e) or str(types.INVALID_PARAMS) in str(e)
9898
finally:
@@ -182,7 +182,7 @@ async def test_client_get_task_result_not_completed():
182182
# Try to get result
183183
try:
184184
await client_session.get_task_result(task_id, types.ServerResult)
185-
assert False, "Should have raised McpError"
185+
assert False, "Should have raised McpError" # pragma: no cover
186186
except Exception as e:
187187
assert "not 'completed'" in str(e) or str(types.INVALID_PARAMS) in str(e)
188188
finally:
@@ -301,7 +301,7 @@ async def test_client_list_tasks_with_cursor():
301301
# List tasks with invalid cursor should raise error
302302
try:
303303
await client_session.list_tasks(cursor="invalid-cursor")
304-
assert False, "Should have raised McpError"
304+
assert False, "Should have raised McpError" # pragma: no cover
305305
except Exception as e:
306306
assert "Invalid cursor" in str(e) or str(types.INVALID_PARAMS) in str(e)
307307
finally:
@@ -389,7 +389,7 @@ async def test_client_delete_task_not_found():
389389
# Try to delete non-existent task
390390
try:
391391
await client_session.delete_task("non-existent")
392-
assert False, "Should have raised McpError"
392+
assert False, "Should have raised McpError" # pragma: no cover
393393
except Exception as e:
394394
assert "Failed to delete task" in str(e) or str(types.INVALID_PARAMS) in str(e)
395395
finally:

tests/server/test_session_tasks.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ async def test_get_task_not_found():
102102
),
103103
types.GetTaskResult,
104104
)
105-
assert False, "Should have raised McpError"
105+
assert False, "Should have raised McpError" # pragma: no cover
106106
except Exception as e:
107107
# Should get an error
108108
assert "Task not found" in str(e) or str(types.INVALID_PARAMS) in str(e)
@@ -203,7 +203,7 @@ async def test_get_task_payload_not_completed():
203203
),
204204
types.ServerResult,
205205
)
206-
assert False, "Should have raised McpError"
206+
assert False, "Should have raised McpError" # pragma: no cover
207207
except Exception as e:
208208
# Should get an error about task not being completed
209209
assert "not 'completed'" in str(e) or str(types.INVALID_PARAMS) in str(e)
@@ -247,7 +247,7 @@ async def test_get_task_payload_not_found():
247247
),
248248
types.ServerResult,
249249
)
250-
assert False, "Should have raised McpError"
250+
assert False, "Should have raised McpError" # pragma: no cover
251251
except Exception as e:
252252
# Should get an error about task not found
253253
assert "Task not found" in str(e) or str(types.INVALID_PARAMS) in str(e)
@@ -431,7 +431,7 @@ async def test_delete_task_not_found():
431431
),
432432
types.EmptyResult,
433433
)
434-
assert False, "Should have raised McpError"
434+
assert False, "Should have raised McpError" # pragma: no cover
435435
except Exception as e:
436436
# Should get an error
437437
assert "Failed to delete task" in str(e) or str(types.INVALID_PARAMS) in str(e)
@@ -478,7 +478,7 @@ async def test_get_task_without_capability():
478478
types.ClientRequest(types.GetTaskRequest(params=types.GetTaskParams(taskId=task_id))),
479479
types.GetTaskResult,
480480
)
481-
assert False, "Should have raised McpError"
481+
assert False, "Should have raised McpError" # pragma: no cover
482482
except Exception as e:
483483
assert "not announced tasks capability" in str(e) or str(types.INVALID_REQUEST) in str(e)
484484
finally:
@@ -520,7 +520,7 @@ async def test_get_task_payload_without_capability():
520520
),
521521
types.ServerResult,
522522
)
523-
assert False, "Should have raised McpError"
523+
assert False, "Should have raised McpError" # pragma: no cover
524524
except Exception as e:
525525
assert "not announced tasks capability" in str(e) or str(types.INVALID_REQUEST) in str(e)
526526
finally:
@@ -560,7 +560,7 @@ async def test_list_tasks_without_capability():
560560
types.ClientRequest(types.ListTasksRequest()),
561561
types.ListTasksResult,
562562
)
563-
assert False, "Should have raised McpError"
563+
assert False, "Should have raised McpError" # pragma: no cover
564564
except Exception as e:
565565
assert "not announced tasks capability" in str(e) or str(types.INVALID_REQUEST) in str(e)
566566
finally:
@@ -602,7 +602,7 @@ async def test_delete_task_without_capability():
602602
),
603603
types.EmptyResult,
604604
)
605-
assert False, "Should have raised McpError"
605+
assert False, "Should have raised McpError" # pragma: no cover
606606
except Exception as e:
607607
assert "not announced tasks capability" in str(e) or str(types.INVALID_REQUEST) in str(e)
608608
finally:
@@ -991,7 +991,7 @@ async def test_get_task_without_task_store():
991991
types.ClientRequest(types.GetTaskRequest(params=types.GetTaskParams(taskId="test-task"))),
992992
types.GetTaskResult,
993993
)
994-
assert False, "Should have raised McpError"
994+
assert False, "Should have raised McpError" # pragma: no cover
995995
except Exception as e:
996996
assert "Task store not configured" in str(e) or str(types.INVALID_REQUEST) in str(e)
997997
finally:
@@ -1033,7 +1033,7 @@ async def test_get_task_payload_without_task_store():
10331033
),
10341034
types.ServerResult,
10351035
)
1036-
assert False, "Should have raised McpError"
1036+
assert False, "Should have raised McpError" # pragma: no cover
10371037
except Exception as e:
10381038
assert "Task store not configured" in str(e) or str(types.INVALID_REQUEST) in str(e)
10391039
finally:
@@ -1073,7 +1073,7 @@ async def test_list_tasks_without_task_store():
10731073
types.ClientRequest(types.ListTasksRequest()),
10741074
types.ListTasksResult,
10751075
)
1076-
assert False, "Should have raised McpError"
1076+
assert False, "Should have raised McpError" # pragma: no cover
10771077
except Exception as e:
10781078
assert "Task store not configured" in str(e) or str(types.INVALID_REQUEST) in str(e)
10791079
finally:
@@ -1115,7 +1115,7 @@ async def test_delete_task_without_task_store():
11151115
),
11161116
types.EmptyResult,
11171117
)
1118-
assert False, "Should have raised McpError"
1118+
assert False, "Should have raised McpError" # pragma: no cover
11191119
except Exception as e:
11201120
assert "Task store not configured" in str(e) or str(types.INVALID_REQUEST) in str(e)
11211121
finally:

tests/shared/test_pending_request.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
from mcp.shared.request import DEFAULT_POLLING_INTERVAL, PendingRequest, TaskHandlerOptions
1010
from mcp.types import CallToolResult, GetTaskResult, TextContent
1111

12+
# Mark all tests in this module to ignore memory stream cleanup warnings
13+
pytestmark = pytest.mark.filterwarnings(
14+
"ignore:Exception ignored.*MemoryObject.*Stream:pytest.PytestUnraisableExceptionWarning"
15+
)
16+
1217

1318
@pytest.fixture
1419
def mock_session() -> MagicMock:
@@ -95,7 +100,7 @@ async def task_created():
95100

96101
async def never_completes():
97102
await asyncio.Future() # Never completes
98-
return sample_result
103+
return sample_result # pragma: no cover
99104

100105
# Set up task status progression
101106
mock_session.get_task.side_effect = [
@@ -135,7 +140,7 @@ async def task_created():
135140

136141
async def never_completes():
137142
await asyncio.Future() # Never completes
138-
return sample_result
143+
return sample_result # pragma: no cover
139144

140145
on_task_created = AsyncMock()
141146
on_task_status = AsyncMock()
@@ -185,7 +190,7 @@ async def task_created():
185190

186191
async def never_completes():
187192
await asyncio.Future() # Never completes
188-
return sample_result
193+
return sample_result # pragma: no cover
189194

190195
# Track polling timestamps
191196
poll_times: list[float] = []
@@ -229,7 +234,7 @@ async def task_created():
229234

230235
async def never_completes():
231236
await asyncio.Future() # Never completes
232-
return sample_result
237+
return sample_result # pragma: no cover
233238

234239
poll_times: list[float] = []
235240

@@ -279,7 +284,7 @@ async def get_result():
279284
# Set up task polling to be slow
280285
async def slow_get_task(task_id: str):
281286
await asyncio.sleep(0.2)
282-
return GetTaskResult(taskId=task_id, status="submitted", pollInterval=100)
287+
return GetTaskResult(taskId=task_id, status="submitted", pollInterval=100) # pragma: no cover
283288

284289
mock_session.get_task.side_effect = slow_get_task
285290

@@ -316,7 +321,7 @@ async def task_created():
316321

317322
async def never_completes():
318323
await asyncio.Future() # Never completes
319-
return sample_result
324+
return sample_result # pragma: no cover
320325

321326
# Set up task polling to complete quickly
322327
mock_session.get_task.return_value = GetTaskResult(taskId="task-6", status="completed", pollInterval=100)
@@ -449,12 +454,12 @@ async def task_created():
449454

450455
async def never_completes():
451456
await asyncio.Future() # Never completes
452-
return sample_result
457+
return sample_result # pragma: no cover
453458

454459
# Set up task polling to never complete
455460
async def never_complete_get_task(task_id: str):
456461
await asyncio.sleep(10)
457-
return GetTaskResult(taskId=task_id, status="submitted", pollInterval=100)
462+
return GetTaskResult(taskId=task_id, status="submitted", pollInterval=100) # pragma: no cover
458463

459464
mock_session.get_task.side_effect = never_complete_get_task
460465

@@ -540,7 +545,7 @@ async def task_created():
540545

541546
async def never_completes():
542547
await asyncio.Future() # Never completes
543-
return sample_result
548+
return sample_result # pragma: no cover
544549

545550
mock_session.get_task.return_value = GetTaskResult(taskId="task-12", status="completed", pollInterval=100)
546551
mock_session.get_task_result.return_value = sample_result
@@ -569,7 +574,7 @@ async def task_created():
569574

570575
async def never_completes():
571576
await asyncio.Future() # Never completes
572-
return sample_result
577+
return sample_result # pragma: no cover
573578

574579
mock_session.get_task.side_effect = [
575580
GetTaskResult(taskId="task-13", status="submitted", pollInterval=50),
@@ -601,7 +606,7 @@ async def task_created():
601606

602607
async def never_completes():
603608
await asyncio.Future() # Never completes
604-
return sample_result
609+
return sample_result # pragma: no cover
605610

606611
mock_session.get_task.side_effect = [
607612
GetTaskResult(taskId="task-14", status="working", pollInterval=50),

tests/test_task_capabilities.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_tasks_capability_includes_tools_when_available(self):
136136
# Register tool handler
137137
@server.call_tool()
138138
async def my_tool(arguments: dict[str, Any]) -> list[types.TextContent]:
139-
return [types.TextContent(type="text", text="test")]
139+
return [types.TextContent(type="text", text="test")] # pragma: no cover
140140

141141
caps = server.get_capabilities(NotificationOptions(), {})
142142
assert caps.tasks is not None
@@ -152,7 +152,7 @@ def test_tasks_capability_includes_resources_when_available(self):
152152
# Register resource handler
153153
@server.read_resource()
154154
async def read_resource(uri: AnyUrl) -> str:
155-
return "test"
155+
return "test" # pragma: no cover
156156

157157
caps = server.get_capabilities(NotificationOptions(), {})
158158
assert caps.tasks is not None
@@ -168,7 +168,7 @@ def test_tasks_capability_includes_prompts_when_available(self):
168168
# Register prompt handler
169169
@server.get_prompt()
170170
async def get_prompt(name: str, arguments: dict[str, str] | None = None) -> types.GetPromptResult:
171-
return types.GetPromptResult(
171+
return types.GetPromptResult( # pragma: no cover
172172
messages=[types.PromptMessage(role="user", content=types.TextContent(type="text", text="test"))]
173173
)
174174

0 commit comments

Comments
 (0)