better web tests

This commit is contained in:
John Lancaster
2026-06-21 21:01:11 -05:00
parent 806bb15bcc
commit 4da2b0ac83
7 changed files with 105 additions and 51 deletions
+21 -17
View File
@@ -1,7 +1,6 @@
from __future__ import annotations
import pytest
from mcp import ClientSession
pytestmark = pytest.mark.smoke
@@ -48,25 +47,27 @@ class TestMcpCatalogSurface:
@pytest.mark.asyncio
async def test_lists_core_catalog_tools(
self,
mcp_session: ClientSession,
mcp_session_factory,
tool_name: str,
) -> None:
"""Ensures tools/list exposes each required core catalog tool name."""
result = await mcp_session.list_tools()
async with mcp_session_factory() as mcp_session:
result = await mcp_session.list_tools()
tool_names = {tool.name for tool in result.tools}
assert tool_name in tool_names
@pytest.mark.asyncio
async def test_calls_search_patterns_tool(self, mcp_session: ClientSession) -> None:
async def test_calls_search_patterns_tool(self, mcp_session_factory) -> None:
"""Ensures tools/call succeeds for search_patterns with basic args."""
result = await mcp_session.call_tool(
"search_patterns",
{
"query": "pytest",
"limit": 5,
},
)
async with mcp_session_factory() as mcp_session:
result = await mcp_session.call_tool(
"search_patterns",
{
"query": "pytest",
"limit": 5,
},
)
assert result.isError is False
assert result.content
@@ -78,19 +79,21 @@ class TestMcpCatalogSurface:
@pytest.mark.asyncio
async def test_lists_catalog_resources(
self,
mcp_session: ClientSession,
mcp_session_factory,
resource_uri: str,
) -> None:
"""Ensures resources/list exposes each required catalog resource URI."""
result = await mcp_session.list_resources()
async with mcp_session_factory() as mcp_session:
result = await mcp_session.list_resources()
resource_uris = {str(resource.uri) for resource in result.resources}
assert resource_uri in resource_uris
@pytest.mark.asyncio
async def test_lists_resource_templates(self, mcp_session: ClientSession) -> None:
async def test_lists_resource_templates(self, mcp_session_factory) -> None:
"""Ensures resources/templates/list includes skills and prompt templates."""
result = await mcp_session.list_resource_templates()
async with mcp_session_factory() as mcp_session:
result = await mcp_session.list_resource_templates()
template_uris = {template.uriTemplate for template in result.resourceTemplates}
assert "resource://skills/{skill_id}/document" in template_uris
@@ -100,8 +103,9 @@ class TestMcpCatalogSurface:
"""Covers MCP prompt discovery surface."""
@pytest.mark.asyncio
async def test_lists_registered_prompts(self, mcp_session: ClientSession) -> None:
async def test_lists_registered_prompts(self, mcp_session_factory) -> None:
"""Ensures prompts/list returns at least one registered prompt."""
result = await mcp_session.list_prompts()
async with mcp_session_factory() as mcp_session:
result = await mcp_session.list_prompts()
assert result.prompts