Skip to content

Commit

Permalink
fix: pass Session class from sqlmodel to sessionmaker to have the rig…
Browse files Browse the repository at this point in the history
…ht session object in tests
  • Loading branch information
Kiryous committed Sep 23, 2024
1 parent aef8d8c commit 8d13e05
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8d13e05

Please sign in to comment.