Remove reliance on create_engine() from TestsExceptionFilter

As we are continuing to add functionality to create_engine()
which in some cases means that backend-specific SQL is
emitted on connect, the practice of repurposing a
SQLite or other engine to act like another one for the
purposes of a test is becoming less feasible.   Here,
TestsExceptionFilter is altered to not rely upon the full
session.create_engine() process for unit tests, instead
calling upon just those listeners being tested.

Change-Id: I0ece42f956c59eab7a6cb86419d8d359250d5e71
This commit is contained in:
Mike Bayer 2014-08-13 14:42:51 -04:00
parent 626d762cbd
commit 977869d553

View File

@ -16,18 +16,20 @@ import contextlib
import itertools
import mock
from oslotest import base as oslo_test_base
import six
import sqlalchemy as sqla
from sqlalchemy.orm import mapper
from oslo.db import exception
from oslo.db.sqlalchemy import exc_filters
from oslo.db.sqlalchemy import session
from oslo.db.sqlalchemy import test_base
_TABLE_NAME = '__tmp__test__tmp__'
class TestsExceptionFilter(test_base.DbTestCase):
class TestsExceptionFilter(oslo_test_base.BaseTestCase):
class Error(Exception):
"""DBAPI base error.
@ -61,6 +63,13 @@ class TestsExceptionFilter(test_base.DbTestCase):
"""
def setUp(self):
super(TestsExceptionFilter, self).setUp()
self.engine = sqla.create_engine("sqlite://")
exc_filters.register_engine(self.engine)
sqla.event.listen(self.engine, "begin", session._begin_ping_listener)
self.engine.connect().close() # initialize
@contextlib.contextmanager
def _dbapi_fixture(self, dialect_name):
engine = self.engine