Skip to content

Commit

Permalink
test: update conftest to use db_conn override on fastapi app
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Oct 25, 2024
1 parent 0c9821d commit 35fb490
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from app.central import central_crud, central_schemas
from app.central.central_schemas import ODKCentralDecrypted, ODKCentralIn
from app.config import encrypt_value, settings
from app.db.database import db_conn
from app.db.enums import TaskStatus, UserRole, get_action_for_status_change
from app.db.models import DbProject, DbTask, DbTaskHistory
from app.main import get_application
Expand Down Expand Up @@ -329,6 +330,10 @@ async def project_data():
@pytest_asyncio.fixture(scope="function")
async def client(app: FastAPI, db: AsyncConnection):
"""The FastAPI test server."""
# Override server db connection to use same as in conftest
# NOTE this is marginally slower, but required else tests fail
app.dependency_overrides[db_conn] = lambda: db

async with LifespanManager(app) as manager:
async with AsyncClient(
transport=ASGITransport(app=manager.app),
Expand Down

0 comments on commit 35fb490

Please sign in to comment.