mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-28 02:10:38 +02:00
test: use McpError assertions now that exception propagation is fixed
This commit is contained in:
parent
60a6f349d9
commit
329a0987b4
1 changed files with 7 additions and 5 deletions
|
|
@ -292,7 +292,7 @@ async def test_middleware_can_access_initialize_result():
|
|||
|
||||
|
||||
async def test_middleware_mcp_error_during_initialization():
|
||||
"""Test that McpError raised in middleware during initialization is sent to responder."""
|
||||
"""Test that McpError raised in middleware during initialization is sent to client."""
|
||||
server = FastMCP("TestServer")
|
||||
|
||||
class ErrorThrowingMiddleware(Middleware):
|
||||
|
|
@ -309,11 +309,12 @@ async def test_middleware_mcp_error_during_initialization():
|
|||
|
||||
server.add_middleware(ErrorThrowingMiddleware())
|
||||
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
with pytest.raises(McpError) as exc_info:
|
||||
async with Client(server):
|
||||
pass
|
||||
|
||||
assert "Invalid initialization parameters" in str(exc_info.value)
|
||||
assert exc_info.value.error.message == "Invalid initialization parameters"
|
||||
assert exc_info.value.error.code == mt.INVALID_PARAMS
|
||||
|
||||
|
||||
async def test_middleware_mcp_error_before_call_next():
|
||||
|
|
@ -332,11 +333,12 @@ async def test_middleware_mcp_error_before_call_next():
|
|||
|
||||
server.add_middleware(EarlyErrorMiddleware())
|
||||
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
with pytest.raises(McpError) as exc_info:
|
||||
async with Client(server):
|
||||
pass
|
||||
|
||||
assert "Request validation failed" in str(exc_info.value)
|
||||
assert exc_info.value.error.message == "Request validation failed"
|
||||
assert exc_info.value.error.code == mt.INVALID_REQUEST
|
||||
|
||||
|
||||
async def test_middleware_mcp_error_after_call_next():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue