Skip to content

Commit

Permalink
Allow to fail instead of skip in DbFixture
Browse files Browse the repository at this point in the history
Tests using DbFixture[1] are currently skipped if the database is
unavailable (no db service, no permissions, etc.) which is fine when
tests are runned by developers but not when runned by the gate jobs.

This change defines the attribute DbFixture.SKIP_ON_UNAVAILABLE_DB: when
the database is unvailable, tests are:

* skipped when SKIP_ON_UNAVAILABLE_DB=True (default, legacy behaviour),
* failed when SKIP_ON_UNAVAILABLE_DB=False.

[1] oslo.db.sqlalchemy.test_base

Change-Id: I067f46417fefe252c650e1e5e590e83547b11b6a
Closes-Bug: #1404093
  • Loading branch information
ZZelle committed Jun 4, 2015
1 parent 42dc936 commit 42de3f6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions oslo_db/sqlalchemy/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ class DbFixture(fixtures.Fixture):
# are referring to them directly.
DBNAME = PASSWORD = USERNAME = 'openstack_citest'

def __init__(self, test):
def __init__(self, test, skip_on_unavailable_db=True):
super(DbFixture, self).__init__()
self.test = test
self.skip_on_unavailable_db = skip_on_unavailable_db

def setUp(self):
super(DbFixture, self).setUp()
Expand All @@ -63,7 +64,11 @@ def setUp(self):
self.test, self.test.resources, testresources._get_result()
)
if not hasattr(self.test, 'db'):
self.test.skip("database '%s' unavailable" % self.DRIVER)
msg = "database '%s' unavailable" % self.DRIVER
if self.skip_on_unavailable_db:
self.test.skip(msg)
else:
self.test.fail(msg)

if self.test.SCHEMA_SCOPE:
self.test.engine = self.test.transaction_engine
Expand All @@ -83,6 +88,7 @@ class DbTestCase(test_base.BaseTestCase):

FIXTURE = DbFixture
SCHEMA_SCOPE = None
SKIP_ON_UNAVAILABLE_DB = True

_schema_resources = {}
_database_resources = {}
Expand Down Expand Up @@ -144,7 +150,9 @@ def resources(self):

def setUp(self):
super(DbTestCase, self).setUp()
self.useFixture(self.FIXTURE(self))
self.useFixture(
self.FIXTURE(
self, skip_on_unavailable_db=self.SKIP_ON_UNAVAILABLE_DB))

def generate_schema(self, engine):
"""Generate schema objects to be used within a test.
Expand Down

0 comments on commit 42de3f6

Please sign in to comment.