Skip test depending on sqlite3 if unavailable
Fixes bug 973626 Add @depends_on_exe to declare a test dependency on the availability of an executable. Skip TestSqlite.test_big_int_mapping if sqlite3 not available on the local PATH. Change-Id: I1b7cf0636f79422f9f31f6a88a493791897a53b4
This commit is contained in:
parent
8e9e0cadaf
commit
d15ec03e5d
|
@ -19,13 +19,15 @@
|
|||
|
||||
|
||||
from glance.tests import functional
|
||||
from glance.tests.utils import execute
|
||||
from glance.tests.utils import execute, depends_on_exe, skip_if_disabled
|
||||
|
||||
|
||||
class TestSqlite(functional.FunctionalTest):
|
||||
"""Functional tests for sqlite-specific logic"""
|
||||
|
||||
@functional.runs_sql
|
||||
@depends_on_exe('sqlite3')
|
||||
@skip_if_disabled
|
||||
def test_big_int_mapping(self):
|
||||
"""Ensure BigInteger not mapped to BIGINT"""
|
||||
self.cleanup()
|
||||
|
|
|
@ -178,6 +178,24 @@ class requires(object):
|
|||
return _runner
|
||||
|
||||
|
||||
class depends_on_exe(object):
|
||||
"""Decorator to skip test if an executable is unavailable"""
|
||||
def __init__(self, exe):
|
||||
self.exe = exe
|
||||
|
||||
def __call__(self, func):
|
||||
def _runner(*args, **kw):
|
||||
cmd = 'which %s' % self.exe
|
||||
exitcode, out, err = execute(cmd, raise_error=False)
|
||||
if exitcode != 0:
|
||||
args[0].disabled_message = 'test requires exe: %s' % self.exe
|
||||
args[0].disabled = True
|
||||
func(*args, **kw)
|
||||
_runner.__name__ = func.__name__
|
||||
_runner.__doc__ = func.__doc__
|
||||
return _runner
|
||||
|
||||
|
||||
def skip_if_disabled(func):
|
||||
"""Decorator that skips a test if test case is disabled."""
|
||||
@functools.wraps(func)
|
||||
|
|
Loading…
Reference in New Issue