From 977869d5535e3c9fe1220f31eaa738912c92ae46 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 13 Aug 2014 14:42:51 -0400 Subject: [PATCH] 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 --- tests/sqlalchemy/test_exc_filters.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/sqlalchemy/test_exc_filters.py b/tests/sqlalchemy/test_exc_filters.py index 60dfe260..b6b13750 100644 --- a/tests/sqlalchemy/test_exc_filters.py +++ b/tests/sqlalchemy/test_exc_filters.py @@ -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