Skip to content

Commit 18f3003

Browse files
fix: Add pragma no cover to unreachable test branches
Mark type-check branches and error handlers in tests as excluded from coverage. These branches handle alternative return types or defensive error conditions that don't execute during normal test runs.
1 parent 36216e0 commit 18f3003

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

tests/issues/test_141_resource_templates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def get_user_profile_missing(user_id: str) -> str: # pragma: no cover
6161
if isinstance(content, ReadResourceContents):
6262
assert content.content == "Post 456 by user 123"
6363
assert content.mime_type == "text/plain"
64-
elif isinstance(content, TextResourceContents):
64+
elif isinstance(content, TextResourceContents): # pragma: no cover
6565
# If it's TextResourceContents (direct return)
6666
assert content.text == "Post 456 by user 123"
6767
assert content.mimeType == "text/plain"
68-
else:
68+
else: # pragma: no cover
6969
# Should not happen for string resources
7070
raise AssertionError(f"Unexpected content type: {type(content)}")
7171

tests/server/fastmcp/servers/test_file_server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ async def test_read_resource_dir(mcp: FastMCP):
100100
if isinstance(res, ReadResourceContents):
101101
assert res.mime_type == "text/plain"
102102
files = json.loads(res.content)
103-
elif isinstance(res, TextResourceContents):
103+
elif isinstance(res, TextResourceContents): # pragma: no cover
104104
assert res.mimeType == "text/plain"
105105
files = json.loads(res.text)
106-
else:
106+
else: # pragma: no cover
107107
raise AssertionError(f"Unexpected content type: {type(res)}")
108108

109109
assert sorted([Path(f).name for f in files]) == [
@@ -126,9 +126,9 @@ async def test_read_resource_file(mcp: FastMCP):
126126

127127
if isinstance(res, ReadResourceContents):
128128
assert res.content == "print('hello world')"
129-
elif isinstance(res, TextResourceContents):
129+
elif isinstance(res, TextResourceContents): # pragma: no cover
130130
assert res.text == "print('hello world')"
131-
else:
131+
else: # pragma: no cover
132132
raise AssertionError(f"Unexpected content type: {type(res)}")
133133

134134

@@ -152,7 +152,7 @@ async def test_delete_file_and_check_resources(mcp: FastMCP, test_dir: Path):
152152

153153
if isinstance(res, ReadResourceContents):
154154
assert res.content == "File not found"
155-
elif isinstance(res, TextResourceContents):
155+
elif isinstance(res, TextResourceContents): # pragma: no cover
156156
assert res.text == "File not found"
157-
else:
157+
else: # pragma: no cover
158158
raise AssertionError(f"Unexpected content type: {type(res)}")

tests/server/fastmcp/test_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,9 @@ async def tool_with_resource(ctx: Context[ServerSession, None]) -> str:
10881088

10891089
if isinstance(r, ReadResourceContents):
10901090
return f"Read resource: {r.content} with mime type {r.mime_type}"
1091-
elif isinstance(r, TextResourceContents):
1091+
elif isinstance(r, TextResourceContents): # pragma: no cover
10921092
return f"Read resource: {r.text} with mime type {r.mimeType}"
1093-
else:
1093+
else: # pragma: no cover
10941094
raise AssertionError(f"Unexpected content type: {type(r)}")
10951095

10961096
async with client_session(mcp._mcp_server) as client:

tests/server/test_read_resource_direct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def temp_file():
1818
yield path
1919
try:
2020
path.unlink()
21-
except FileNotFoundError:
21+
except FileNotFoundError: # pragma: no cover
2222
pass
2323

2424

0 commit comments

Comments
 (0)