Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Add setup and teardown database for tests #626

Merged
merged 2 commits into from
Mar 1, 2024
Merged
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
12 changes: 10 additions & 2 deletions src/backend/app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

import pytest
from fastapi.testclient import TestClient
from sqlmodel import Session
from sqlmodel import Session, delete

from app.core.config import settings
from app.db.engine import engine
from app.db.init_db import init_db
from app.main import app
from app.models import Item, User
from app.tests.utils.user import authentication_token_from_email
from app.tests.utils.utils import get_superuser_token_headers


@pytest.fixture(scope="session")
@pytest.fixture(scope="session", autouse=True)
def db() -> Generator:
with Session(engine) as session:
init_db(session)
yield session
statement = delete(Item)
session.execute(statement)
statement = delete(User)
session.execute(statement)
session.commit()


@pytest.fixture(scope="module")
Expand Down