File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ def choose_sa_engine(
5050 return primary_engine
5151
5252
53- def create_session (engine : sa .AsyncEngine ) -> sa .AsyncSession :
53+ def create_session (engine : sa .AsyncEngine | sa . AsyncConnection ) -> sa .AsyncSession :
5454 # join_transaction_mode is inert in production (the session binds to an engine); when tests bind
5555 # the session to a connection already in a transaction, it makes the session own a savepoint so
5656 # the outer transaction survives commits and the per-test rollback stays clean.
Original file line number Diff line number Diff line change 55from asgi_lifespan import LifespanManager
66from httpx import ASGITransport , AsyncClient
77from polyfactory .factories .sqlalchemy_factory import SQLAlchemyFactory
8- from sqlalchemy .ext .asyncio import AsyncSession
98
109from app import ioc
1110from app .application import build_app
12- from app .resources .db import create_primary_sa_engine
11+ from app .resources .db import create_primary_sa_engine , create_session
1312
1413
1514if typing .TYPE_CHECKING :
1615 import fastapi
1716 import modern_di
17+ from sqlalchemy .ext .asyncio import AsyncSession
1818
1919
2020@pytest .fixture
@@ -50,12 +50,7 @@ async def db_session(di_container: modern_di.Container) -> typing.AsyncIterator[
5050 di_container .override (ioc .Dependencies .dynamic_engine , connection )
5151
5252 try :
53- yield AsyncSession (
54- connection ,
55- expire_on_commit = False ,
56- autoflush = False ,
57- join_transaction_mode = "create_savepoint" ,
58- )
53+ yield create_session (connection )
5954 finally :
6055 if connection .in_transaction ():
6156 await transaction .rollback ()
You can’t perform that action at this time.
0 commit comments