Skip to content

Commit dbecaa0

Browse files
committed
fix: restore pragmas for lines not covered in CI
Restore # pragma: no cover and # pragma: no branch on lines that are not actually covered in CI (platform-dependent, branch coverage, or unreachable code paths).
1 parent 79cc3b1 commit dbecaa0

File tree

10 files changed

+24
-24
lines changed

10 files changed

+24
-24
lines changed

tests/client/auth/extensions/test_client_credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self):
2626
async def get_tokens(self) -> OAuthToken | None:
2727
return self._tokens
2828

29-
async def set_tokens(self, tokens: OAuthToken) -> None:
29+
async def set_tokens(self, tokens: OAuthToken) -> None: # pragma: no cover
3030
self._tokens = tokens
3131

3232
async def get_client_info(self) -> OAuthClientInformationFull | None: # pragma: no cover

tests/client/test_stdio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def handle_term(sig, frame):
481481
await anyio.sleep(0.5)
482482

483483
# Verify child is writing
484-
if os.path.exists(marker_file):
484+
if os.path.exists(marker_file): # pragma: no branch
485485
size1 = os.path.getsize(marker_file)
486486
await anyio.sleep(0.3)
487487
size2 = os.path.getsize(marker_file)

tests/client/transports/test_memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def greet(name: str) -> str:
4040
return f"Hello, {name}!"
4141

4242
@server.resource("test://resource")
43-
def test_resource() -> str:
43+
def test_resource() -> str: # pragma: no cover
4444
"""A test resource."""
4545
return "Test content"
4646

tests/issues/test_1027_win_unreachable_cleanup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def echo(text: str) -> str:
102102

103103
# Give server a moment to complete cleanup
104104
with anyio.move_on_after(5.0):
105-
while not Path(cleanup_marker).exists():
105+
while not Path(cleanup_marker).exists(): # pragma: no cover
106106
await anyio.sleep(0.1)
107107

108108
# Verify cleanup marker was created - this works now that stdio_client
@@ -113,9 +113,9 @@ def echo(text: str) -> str:
113113
finally:
114114
# Clean up files
115115
for path in [server_script, startup_marker, cleanup_marker]:
116-
try:
116+
try: # pragma: no cover
117117
Path(path).unlink()
118-
except FileNotFoundError:
118+
except FileNotFoundError: # pragma: no cover
119119
pass
120120

121121

@@ -224,7 +224,7 @@ def echo(text: str) -> str:
224224

225225
# Check if cleanup ran
226226
with anyio.move_on_after(5.0):
227-
while not Path(cleanup_marker).exists():
227+
while not Path(cleanup_marker).exists(): # pragma: no cover
228228
await anyio.sleep(0.1)
229229

230230
# Verify the cleanup ran - stdin closure enables graceful shutdown
@@ -234,7 +234,7 @@ def echo(text: str) -> str:
234234
finally:
235235
# Clean up files
236236
for path in [server_script, startup_marker, cleanup_marker]:
237-
try:
237+
try: # pragma: no cover
238238
Path(path).unlink()
239-
except FileNotFoundError:
239+
except FileNotFoundError: # pragma: no cover
240240
pass

tests/server/fastmcp/auth/test_auth_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async def load_access_token(self, token: str) -> AccessToken | None:
172172

173173
async def revoke_token(self, token: AccessToken | RefreshToken) -> None:
174174
match token:
175-
case RefreshToken():
175+
case RefreshToken(): # pragma: no cover
176176
# Remove the refresh token
177177
del self.refresh_tokens[token.token]
178178

tests/server/fastmcp/resources/test_file_resources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def temp_file():
1818
f.write(content)
1919
path = Path(f.name).resolve()
2020
yield path
21-
try:
21+
try: # pragma: no cover
2222
path.unlink()
23-
except FileNotFoundError:
23+
except FileNotFoundError: # pragma: no cover
2424
pass # File was already deleted by the test
2525

2626

tests/server/fastmcp/resources/test_resource_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def temp_file():
1818
f.write(content)
1919
path = Path(f.name).resolve()
2020
yield path
21-
try:
21+
try: # pragma: no cover
2222
path.unlink()
23-
except FileNotFoundError:
23+
except FileNotFoundError: # pragma: no cover
2424
pass # File was already deleted by the test
2525

2626

tests/server/fastmcp/test_elicitation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def test_stdio_elicitation():
6868
async def elicitation_callback(context: RequestContext[ClientSession, None], params: ElicitRequestParams):
6969
if params.message == "Tool wants to ask: What is your name?":
7070
return ElicitResult(action="accept", content={"answer": "Test User"})
71-
else:
71+
else: # pragma: no cover
7272
raise ValueError(f"Unexpected elicitation message: {params.message}")
7373

7474
await call_tool_and_assert(
@@ -100,7 +100,7 @@ def create_validation_tool(name: str, schema_class: type[BaseModel]):
100100
async def tool(ctx: Context[ServerSession, None]) -> str:
101101
try:
102102
await ctx.elicit(message="This should fail validation", schema=schema_class)
103-
return "Should not reach here"
103+
return "Should not reach here" # pragma: no cover
104104
except TypeError as e:
105105
return f"Validation failed as expected: {str(e)}"
106106

@@ -191,7 +191,7 @@ class InvalidOptionalSchema(BaseModel):
191191
async def invalid_optional_tool(ctx: Context[ServerSession, None]) -> str:
192192
try:
193193
await ctx.elicit(message="This should fail", schema=InvalidOptionalSchema)
194-
return "Should not reach here"
194+
return "Should not reach here" # pragma: no cover
195195
except TypeError as e:
196196
return f"Validation failed: {str(e)}"
197197

tests/shared/test_streamable_http.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def extract_protocol_version_from_sse(response: requests.Response) -> str:
7979
if line.startswith("data: "):
8080
init_data = json.loads(line[6:])
8181
return init_data["result"]["protocolVersion"]
82-
raise ValueError("Could not extract protocol version from SSE response")
82+
raise ValueError("Could not extract protocol version from SSE response") # pragma: no cover
8383

8484

8585
# Simple in-memory event store for testing
@@ -97,7 +97,7 @@ async def store_event(self, stream_id: StreamId, message: types.JSONRPCMessage |
9797
self._events.append((stream_id, event_id, message))
9898
return event_id
9999

100-
async def replay_events_after(
100+
async def replay_events_after( # pragma: no cover
101101
self,
102102
last_event_id: EventId,
103103
send_callback: EventCallback,
@@ -1154,7 +1154,7 @@ async def test_streamable_http_client_session_termination(basic_server: None, ba
11541154
assert len(tools.tools) == 10
11551155

11561156
headers: dict[str, str] = {}
1157-
if captured_session_id:
1157+
if captured_session_id: # pragma: no branch
11581158
headers[MCP_SESSION_ID_HEADER] = captured_session_id
11591159

11601160
async with create_mcp_http_client(headers=headers) as httpx_client:
@@ -1218,7 +1218,7 @@ async def mock_delete(self: httpx.AsyncClient, *args: Any, **kwargs: Any) -> htt
12181218
assert len(tools.tools) == 10
12191219

12201220
headers: dict[str, str] = {}
1221-
if captured_session_id:
1221+
if captured_session_id: # pragma: no branch
12221222
headers[MCP_SESSION_ID_HEADER] = captured_session_id
12231223

12241224
async with create_mcp_http_client(headers=headers) as httpx_client:
@@ -1312,9 +1312,9 @@ async def run_tool():
13121312

13131313
# Now resume the session with the same mcp-session-id and protocol version
13141314
headers: dict[str, Any] = {}
1315-
if captured_session_id:
1315+
if captured_session_id: # pragma: no branch
13161316
headers[MCP_SESSION_ID_HEADER] = captured_session_id
1317-
if captured_protocol_version:
1317+
if captured_protocol_version: # pragma: no branch
13181318
headers[MCP_PROTOCOL_VERSION_HEADER] = captured_protocol_version
13191319

13201320
async with create_mcp_http_client(headers=headers) as httpx_client:

tests/shared/test_ws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def server(server_port: int) -> Generator[None, None, None]:
121121
# Signal the server to stop
122122
proc.kill()
123123
proc.join(timeout=2)
124-
if proc.is_alive():
124+
if proc.is_alive(): # pragma: no cover
125125
print("server process failed to terminate")
126126

127127

0 commit comments

Comments
 (0)