Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/resources/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def choose_sa_engine(
return primary_engine


def create_session(engine: sa.AsyncEngine) -> sa.AsyncSession:
def create_session(engine: sa.AsyncEngine | sa.AsyncConnection) -> sa.AsyncSession:
# join_transaction_mode is inert in production (the session binds to an engine); when tests bind
# the session to a connection already in a transaction, it makes the session own a savepoint so
# the outer transaction survives commits and the per-test rollback stays clean.
Expand Down
9 changes: 2 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from app import ioc
from app.application import build_app
from app.resources.db import create_primary_sa_engine
from app.resources.db import create_primary_sa_engine, create_session


if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -50,12 +50,7 @@ async def db_session(di_container: modern_di.Container) -> typing.AsyncIterator[
di_container.override(ioc.Dependencies.dynamic_engine, connection)

try:
yield AsyncSession(
connection,
expire_on_commit=False,
autoflush=False,
join_transaction_mode="create_savepoint",
)
yield create_session(connection)
finally:
if connection.in_transaction():
await transaction.rollback()
Expand Down
Loading