From 8d13e0512deef114c2892c55c6043feca92ddb63 Mon Sep 17 00:00:00 2001 From: Kirill Chernakov Date: Mon, 23 Sep 2024 21:32:53 +0400 Subject: [PATCH] fix: pass Session class from sqlmodel to sessionmaker to have the right session object in tests --- tests/conftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0a5088d84..52ed88055 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,7 +13,7 @@ from pytest_docker.plugin import get_docker_services from sqlalchemy.orm import sessionmaker from sqlalchemy.pool import StaticPool -from sqlmodel import SQLModel, create_engine +from sqlmodel import SQLModel, Session, create_engine from starlette_context import context, request_cycle_context # This import is required to create the tables @@ -182,7 +182,8 @@ def db_session(request): os.environ["DATABASE_CONNECTION_STRING"] = db_connection_string # Create a session - SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=mock_engine) + # Passing class_=Session to use the Session class from sqlmodel (https://github.com/fastapi/sqlmodel/issues/75#issuecomment-2109911909) + SessionLocal = sessionmaker(class_=Session, autocommit=False, autoflush=False, bind=mock_engine) session = SessionLocal() # Prepopulate the database with test data