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:
parent
fb87326d66
commit
87aaebe475
1 changed files with 3 additions and 4 deletions
|
|
@ -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.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue