Skip to content

Commit 6e77131

Browse files
committed
Add expire_on_commit option to sessions
When initialising the SessionFixture, allow call sites to set the expire_on_commit flag passed to the session factory.
1 parent 4269e14 commit 6e77131

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

dbtesttools/fixtures.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,17 @@ class SessionFixture(fixtures.Fixture):
210210
:param debug: If true, send all DB statements emitted to the log.
211211
"""
212212

213-
def __init__(self, database_fixture, future=False, debug=False):
213+
def __init__(
214+
self,
215+
database_fixture,
216+
future=False,
217+
debug=False,
218+
expire_on_commit=True,
219+
):
214220
super().__init__()
215221
self.database = database_fixture
216222
self.future = future
223+
self.expire_on_commit = expire_on_commit
217224
if debug:
218225
self.database.engine.echo = True
219226
from logging import Formatter, getLogger
@@ -228,7 +235,7 @@ def setUp(self):
228235
self.connection = self.database.connect()
229236
self.txn = self.connection.begin()
230237
self.configure_session()
231-
self.session = self.Session()
238+
self.session = self.Session(expire_on_commit=self.expire_on_commit)
232239
# Even if the DB won't do savepoints, begin a nested transaction
233240
# anyway. This makes SQLite tests pass.
234241
self.set_up_savepoint()

0 commit comments

Comments
 (0)