Open
Description
Describe the bug
Currently because of broken lifespan integration in pytest, you need to duplicate code like:
@pytest_asyncio.fixture(scope="session")
async def app_client(app):
await create_index_templates()
await create_collection_index()
async with AsyncClient(
transport=ASGITransport(app=app), base_url="http://test-server"
) as c:
yield c
despite having:
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Lifespan handler for FastAPI app. Initializes index templates and collections at startup."""
await create_index_templates()
await create_collection_index()
yield
It's fairly simple to fix, feel free to use this code:
- https://github.com/openstreetmap-ng/openstreetmap-ng/blob/main/tests/utils/lifespan_manager.py
- https://github.com/openstreetmap-ng/openstreetmap-ng/blob/2ae47ba66659a4993a78acffa0a7126f95f87abc/tests/conftest.py#L51-L59
This should make the tests more consistent with the actual deployment.
Metadata
Metadata
Assignees
Labels
No labels