def connection(custom_settings): """ sets up a SQLAlchemy engine and returns a connection to the database. The connection string used for testing can be specified via the ``KOTTI_TEST_DB_STRING`` environment variable. The ``custom_settings`` fixture is needed to allow users to import their models easily instead of having to override the ``connection``. """ # the following setup is based on `kotti.resources.initialize_sql`, # except that it explicitly binds the session to a specific connection # enabling us to use savepoints independent from the orm, thus allowing # to `rollback` after using `transaction.commit`... from sqlalchemy import create_engine from kotti import DBSession from kotti import metadata from kotti.resources import _adjust_for_engine from kotti.testing import testing_db_url engine = create_engine(testing_db_url()) _adjust_for_engine(engine) connection = engine.connect() DBSession.registry.clear() DBSession.configure(bind=connection) metadata.bind = engine return connection