Skip to content

Commit

Permalink
Add expire_on_commit option to sessions
Browse files Browse the repository at this point in the history
When initialising the SessionFixture, allow call sites to set the
expire_on_commit flag passed to the session factory.
  • Loading branch information
juledwar committed Nov 11, 2024
1 parent 4269e14 commit 6e77131
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dbtesttools/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,17 @@ class SessionFixture(fixtures.Fixture):
:param debug: If true, send all DB statements emitted to the log.
"""

def __init__(self, database_fixture, future=False, debug=False):
def __init__(
self,
database_fixture,
future=False,
debug=False,
expire_on_commit=True,
):
super().__init__()
self.database = database_fixture
self.future = future
self.expire_on_commit = expire_on_commit
if debug:
self.database.engine.echo = True
from logging import Formatter, getLogger
Expand All @@ -228,7 +235,7 @@ def setUp(self):
self.connection = self.database.connect()
self.txn = self.connection.begin()
self.configure_session()
self.session = self.Session()
self.session = self.Session(expire_on_commit=self.expire_on_commit)
# Even if the DB won't do savepoints, begin a nested transaction
# anyway. This makes SQLite tests pass.
self.set_up_savepoint()
Expand Down

0 comments on commit 6e77131

Please sign in to comment.