test changes

This commit is contained in:
John Lancaster
2026-08-29 22:28:55 -05:00
parent c31a78206f
commit f5b65ecf0a
6 changed files with 64 additions and 85 deletions
+12 -41
View File
@@ -1,47 +1,18 @@
import socket
import sys
from collections.abc import Iterator
from collections.abc import AsyncIterator
import pytest
from xprocess import ProcessStarter
from xprocess import XProcess
from asgi_lifespan import LifespanManager
from fastmcp.utilities.tests import ASGIServer
SERVER_HOST = "127.0.0.1"
from personal_mcp.app import create_app
@pytest.fixture
def fastapi_server_url(xprocess: XProcess, unused_tcp_port: int) -> Iterator[str]:
class ServerStarter(ProcessStarter):
timeout = 10
terminate_on_interrupt = True
@property
def args(self) -> list[str]:
return [
sys.executable,
"-m",
"uvicorn",
"personal_mcp.app:create_app",
"--factory",
"--host",
SERVER_HOST,
"--port",
str(unused_tcp_port),
"--log-level",
"warning",
"--no-access-log",
]
def startup_check(self) -> bool:
try:
with socket.create_connection((SERVER_HOST, unused_tcp_port), timeout=0.1):
return True
except OSError:
return False
process_name = f"personal-mcp-http-{unused_tcp_port}"
xprocess.ensure(process_name, ServerStarter)
try:
yield f"http://{SERVER_HOST}:{unused_tcp_port}/mcp"
finally:
xprocess.getinfo(process_name).terminate()
async def http_server() -> AsyncIterator[ASGIServer]:
app = create_app()
async with LifespanManager(app):
yield ASGIServer(
url="http://127.0.0.1/mcp",
app=app,
transport_type="http",
)