From c96469b1f54143d90d4bd7f612ffc6683a7b5c78 Mon Sep 17 00:00:00 2001 From: PuQing Date: Sat, 17 Feb 2024 01:12:21 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=84=20refactor:=20=20Add=20database=20?= =?UTF-8?q?initialization=20in=20session=20fixture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/app/conftest.py | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/backend/app/app/conftest.py b/backend/app/app/conftest.py index 0042802..af5d244 100644 --- a/backend/app/app/conftest.py +++ b/backend/app/app/conftest.py @@ -3,6 +3,7 @@ from sqlmodel import Session, SQLModel, create_engine from app.core.config import settings +from app.db.init_db import init_db from app.web.api.deps import get_db from app.web.application import get_app @@ -13,7 +14,9 @@ def session_fixture(): f"postgresql+psycopg://{settings.POSTGRES_USER}:{settings.POSTGRES_PASSWORD}@bemore-db/{settings.POSTGRES_DB}", ) SQLModel.metadata.create_all(engine) + with Session(engine) as session: + init_db(session) yield session @@ -38,30 +41,3 @@ def get_session_override(): client = AsyncClient(app=app, base_url="http://localhost:8000") yield client app.dependency_overrides.clear() - - -# @pytest.fixture() -# def fastapi_app() -> FastAPI: -# """ -# Fixture for creating FastAPI app. - -# :return: fastapi app with mocked dependencies. -# """ -# application = get_app() -# return application # noqa: WPS331 - - -# @pytest.fixture(name="client") -# async def client_fixture( -# fastapi_app: FastAPI, -# ) -> AsyncGenerator[AsyncClient, None]: -# """ -# Fixture that creates client for requesting server. - -# :param fastapi_app: the application. -# :yield: client for the app. -# """ -# async with AsyncClient( -# app=fastapi_app, base_url="http://localhost:8000" -# ) as ac: -# yield ac