Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ jobs:
print("infra-ready")
PY

- name: Prepare test database schema
run: |
python - <<'PY'
import asyncio
from src.models.database import Base
from src.models.db import engine

async def main() -> None:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
await engine.dispose()

asyncio.run(main())
print("schema-ready")
PY

- name: Run tests
run: pytest -q -m "not integration"

Expand Down Expand Up @@ -136,6 +152,22 @@ jobs:
print("infra-ready")
PY

- name: Prepare test database schema
run: |
python - <<'PY'
import asyncio
from src.models.database import Base
from src.models.db import engine

async def main() -> None:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
await engine.dispose()

asyncio.run(main())
print("schema-ready")
PY

- name: Run compare blackbox integration test
run: pytest -q -m integration tests/integration/test_compare_blackbox.py

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ select = ["E", "F", "I", "N", "W", "UP"]
testpaths = ["tests"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "session"
asyncio_default_test_loop_scope = "session"
markers = [
"integration: tests that require real infra/services",
]
Expand Down
17 changes: 14 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from httpx import ASGITransport, AsyncClient

from src.api.main import app
from src.models.database import Base
from src.models.db import engine


@pytest.fixture(scope="session")
Expand All @@ -19,9 +21,18 @@ def event_loop():
loop.close()


@pytest.fixture(scope="session", autouse=True)
async def ensure_db_schema():
"""Ensure required tables exist even when app lifespan is not triggered."""
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
yield


@pytest.fixture
async def client():
"""Async test client for the FastAPI app."""
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
yield ac
async with app.router.lifespan_context(app):
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
yield ac