options=None,
asyncio=False,
transfer_staticpool=False,
+ _sqlite_savepoint=False,
):
if asyncio:
+ assert not _sqlite_savepoint
from sqlalchemy.ext.asyncio import (
create_async_engine as create_engine,
)
if not options:
use_reaper = True
scope = "function"
+ sqlite_savepoint = False
else:
use_reaper = options.pop("use_reaper", True)
scope = options.pop("scope", "function")
+ sqlite_savepoint = options.pop("sqlite_savepoint", False)
url = url or config.db.url
engine = create_engine(url, **options)
+ if sqlite_savepoint and engine.name == "sqlite":
+ # apply SQLite savepoint workaround
+ @event.listens_for(engine, "connect")
+ def do_connect(dbapi_connection, connection_record):
+ dbapi_connection.isolation_level = None
+
+ @event.listens_for(engine, "begin")
+ def do_begin(conn):
+ conn.exec_driver_sql("BEGIN")
+
if transfer_staticpool:
from sqlalchemy.pool import StaticPool
class JoinIntoAnExternalTransactionFixture:
"""Test the "join into an external transaction" examples"""
- __leave_connections_for_teardown__ = True
-
def setup_test(self):
- self.engine = testing.db
+ self.engine = engines.testing_engine(
+ options={"use_reaper": False, "sqlite_savepoint": True}
+ )
self.connection = self.engine.connect()
self.metadata = MetaData()
# bind an individual Session to the connection
self.session = Session(bind=self.connection)
- if testing.requires.savepoints.enabled:
+ if testing.requires.compat_savepoints.enabled:
self.nested = self.connection.begin_nested()
@event.listens_for(self.session, "after_transaction_end")
if self.trans.is_active:
self.trans.rollback()
- @testing.requires.savepoints
+ @testing.requires.compat_savepoints
def test_something_with_context_managers(self):
A = self.A
# bind an individual Session to the connection
self.session = Session(bind=self.connection)
- if testing.requires.savepoints.enabled:
+ if testing.requires.compat_savepoints.enabled:
# start the session in a SAVEPOINT...
self.session.begin_nested()
"savepoints not supported",
)
+ @property
+ def compat_savepoints(self):
+ """Target database must support savepoints, or a compat
+ recipe e.g. for sqlite will be used"""
+
+ return skip_if(
+ ["sybase", ("mysql", "<", (5, 0, 3))],
+ "savepoints not supported",
+ )
+
@property
def savepoints_w_release(self):
return self.savepoints + skip_if(