Join the session into the outer transaction

With "create_savepoint", commits inside a test case
only release a savepoint, so the final rollback no longer warns
This commit is contained in:
Alexander Hess 2026-11-30 10:23:39 +01:00
commit 87aaebe475
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -5,7 +5,6 @@ in the CLI layer need access to the database.
""" """
import os import os
import warnings
import pytest import pytest
import sqlalchemy as sa import sqlalchemy as sa
@ -92,7 +91,8 @@ def db_session(db_connection):
# Create a session bound to the same connection as the `transaction`. # Create a session bound to the same connection as the `transaction`.
# Using any other session would not result in the roll back. # Using any other session would not result in the roll back.
session = orm.sessionmaker()(bind=db_connection) # Commits inside a test case then only release a savepoint.
session = orm.Session(bind=db_connection, join_transaction_mode="create_savepoint")
# Monkey patch the package's global `session` object, # Monkey patch the package's global `session` object,
# which is used heavily in the code base. # which is used heavily in the code base.
@ -104,8 +104,7 @@ def db_session(db_connection):
finally: finally:
session.close() session.close()
with warnings.catch_warnings(record=True): transaction.rollback()
transaction.rollback()
# Import the fixtures from the `fake_data` sub-package. # Import the fixtures from the `fake_data` sub-package.