Publish curated ITWorx-ModelForge source from 990401737f96c8d46a9f7b0d84994516cadcb6a0
This commit is contained in:
1 parent
7082ab955a
commit
848f0d8f8a
434 files changed
+67298
-4315
No files matched your search
@@ -0,0 +1,32 @@
|
||||
"""Opt-in HTTP fixture: real middleware/routes, no ambient startup or database."""
|
||||
from collections.abc import AsyncIterator, Iterator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
|
||||
from modelforge_api.db import engine as ambient_engine
|
||||
from modelforge_api.main import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def isolated_http_contract(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
|
||||
# These exercise the real HTTP stack with fake collectors, not application startup.
|
||||
# Do not run reconciliation, schema validation or background polling against .env.
|
||||
@asynccontextmanager
|
||||
async def contract_lifespan(_app: FastAPI) -> AsyncIterator[None]:
|
||||
yield
|
||||
|
||||
ambient_connections: list[str] = []
|
||||
|
||||
def reject_ambient_connection(*args: object, **kwargs: object) -> None:
|
||||
ambient_connections.append("connection attempted")
|
||||
raise AssertionError("HTTP contract tests must not use the ambient database")
|
||||
|
||||
monkeypatch.setattr(ambient_engine, "connect", reject_ambient_connection)
|
||||
monkeypatch.setattr(ambient_engine, "raw_connection", reject_ambient_connection)
|
||||
monkeypatch.setattr(app.router, "lifespan_context", contract_lifespan)
|
||||
# Restore the original mapping (including other tests' overrides) on teardown.
|
||||
monkeypatch.setattr(app, "dependency_overrides", {})
|
||||
yield
|
||||
assert not ambient_connections
|
||||
Reference in new issue
Block a user