in process fixes
This commit is contained in:
@@ -32,7 +32,6 @@ test = [
|
||||
"pytest>=9.1.1",
|
||||
"pytest-asyncio>=1.4.0",
|
||||
"pytest-cov>=7.1.0",
|
||||
"pytest-env>=1.1.5",
|
||||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
@@ -44,7 +43,6 @@ markers = [
|
||||
"integration: framework or component integration tests",
|
||||
"smoke: thin critical-path checks",
|
||||
]
|
||||
env = ["PERSONAL_MCP_TEST_HTTP_URL=https://mcp.john-stream.com/mcp"]
|
||||
|
||||
[tool.ty.src]
|
||||
include = ["src", "tests"]
|
||||
|
||||
+11
-17
@@ -1,6 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
@@ -27,27 +26,22 @@ async def client() -> AsyncIterator[AsyncClient]:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mcp_endpoint_url() -> str:
|
||||
"""Provides the MCP endpoint URL for SDK-based client sessions."""
|
||||
return os.getenv("PERSONAL_MCP_TEST_HTTP_URL", "")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mcp_session_factory(mcp_endpoint_url: str):
|
||||
"""Provides a context manager factory for MCP SDK sessions.
|
||||
|
||||
Keeping stream/client/session enter and exit in the test task avoids
|
||||
cross-task cancel scope teardown errors from async generator fixtures.
|
||||
"""
|
||||
if not mcp_endpoint_url:
|
||||
pytest.skip("Set PERSONAL_MCP_TEST_HTTP_URL to run SDK-backed MCP endpoint tests.")
|
||||
def mcp_session_factory():
|
||||
"""Provides an in-process context manager factory for MCP SDK sessions."""
|
||||
|
||||
@asynccontextmanager
|
||||
async def create_session(*, initialize: bool = True) -> AsyncIterator[ClientSession]:
|
||||
app = create_app()
|
||||
mcp_url = f"http://testserver{app.state.settings.mcp_route}"
|
||||
async with (
|
||||
AsyncClient(timeout=10.0) as http_client,
|
||||
app.router.lifespan_context(app),
|
||||
AsyncClient(
|
||||
transport=ASGITransport(app=app),
|
||||
base_url="http://testserver",
|
||||
timeout=10.0,
|
||||
) as http_client,
|
||||
streamable_http_client(
|
||||
mcp_endpoint_url,
|
||||
mcp_url,
|
||||
http_client=http_client,
|
||||
) as (read_stream, write_stream, _),
|
||||
ClientSession(read_stream, write_stream) as session,
|
||||
|
||||
@@ -1131,7 +1131,6 @@ test = [
|
||||
{ name = "pytest" },
|
||||
{ name = "pytest-asyncio" },
|
||||
{ name = "pytest-cov" },
|
||||
{ name = "pytest-env" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
@@ -1155,7 +1154,6 @@ test = [
|
||||
{ name = "pytest", specifier = ">=9.1.1" },
|
||||
{ name = "pytest-asyncio", specifier = ">=1.4.0" },
|
||||
{ name = "pytest-cov", specifier = ">=7.1.0" },
|
||||
{ name = "pytest-env", specifier = ">=1.1.5" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1435,19 +1433,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/9d/7a/d968e294073affff457b041c2be9868a40c1c71f4a35fcc1e45e5493067b/pytest_cov-7.1.0-py3-none-any.whl", hash = "sha256:a0461110b7865f9a271aa1b51e516c9a95de9d696734a2f71e3e78f46e1d4678", size = 22876, upload-time = "2026-03-21T20:11:14.438Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pytest-env"
|
||||
version = "1.6.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "pytest" },
|
||||
{ name = "python-dotenv" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ff/69/4db1c30625af0621df8dbe73797b38b6d1b04e15d021dd5d26a6d297f78c/pytest_env-1.6.0.tar.gz", hash = "sha256:ac02d6fba16af54d61e311dd70a3c61024a4e966881ea844affc3c8f0bf207d3", size = 16163, upload-time = "2026-03-12T22:39:43.78Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/27/16/ad52f56b96d851a2bcfdc1e754c3531341885bd7177a128c13ff2ca72ab4/pytest_env-1.6.0-py3-none-any.whl", hash = "sha256:1e7f8a62215e5885835daaed694de8657c908505b964ec8097a7ce77b403d9a3", size = 10400, upload-time = "2026-03-12T22:39:41.887Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-discovery"
|
||||
version = "1.4.2"
|
||||
|
||||
@@ -106,6 +106,7 @@ nav = [
|
||||
{ "Pytest" = [
|
||||
{ "Overview" = "skills/pytest-scaffolding/SKILL.md" },
|
||||
{ "Docs" = "skills/pytest-scaffolding/references/pytest-docs.md" },
|
||||
{ "AsyncIO" = "skills/pytest-scaffolding/references/asyncio-testing.md" },
|
||||
] },
|
||||
{ "Logging" = [
|
||||
{ "Overview" = "skills/python-logging-dictconfig/SKILL.md" },
|
||||
|
||||
Reference in New Issue
Block a user