Browse Source
✅ Add setup and teardown database for tests (#626)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
pull/13907/head
Esteban Maya
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
10 additions and
2 deletions
-
src/backend/app/tests/conftest.py
|
|
@ -2,19 +2,27 @@ from collections.abc import Generator |
|
|
|
|
|
|
|
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") |
|
|
|