def __should_skip_for(self, cls):
if hasattr(cls, '__requires__'):
def test_suite(): return 'ok'
+ test_suite.__name__ = cls.__name__
for requirement in cls.__requires__:
check = getattr(requires, requirement)
if check(test_suite)() != 'ok':
print "'%s' unsupported on DB implementation '%s'" % (
cls.__class__.__name__, testing.db.name)
return True
+
if getattr(cls, '__only_on__', None):
spec = testing.db_spec(*util.to_list(cls.__only_on__))
if not spec(testing.db):
print "'%s' skipped by %s" % (
cls.__class__.__name__, c.__name__)
return True
+
for rule in getattr(cls, '__excluded_on__', ()):
if testing._is_excluded(*rule):
print "'%s' unsupported on DB %s version %s" % (
skip_if
import testing
+import sys
def deferrable_constraints(fn):
"""Target database must support derferable constraints."""
def denormalized_names(fn):
"""Target database must have 'denormalized', i.e. UPPERCASE as case insensitive names."""
- return skip_if(lambda: not testing.db.dialect.requires_name_normalize)(fn)
+ return skip_if(
+ lambda: not testing.db.dialect.requires_name_normalize,
+ "Backend does not require denomralized names."
+ )(fn)
def schemas(fn):
"""Target database must support external schemas, and have one named 'test_schema'."""
exclude('mysql', '<', (4, 1, 1), 'no unicode connection support'),
)
+def python2(fn):
+ return _chain_decorators_on(
+ fn,
+ skip_if(
+ lambda: sys.version_info >= (3,),
+ "Python version 2.xx is required."
+ )
+ )
+
+def _has_sqlite():
+ from sqlalchemy import create_engine
+ try:
+ e = create_engine('sqlite://')
+ return True
+ except ImportError:
+ return False
+
+def sqlite(fn):
+ return _chain_decorators_on(
+ fn,
+ skip_if(lambda: not _has_sqlite())
+ )
+
def skip_if(predicate, reason=None):
"""Skip a test if predicate is true."""
reason = reason or predicate.__name__
+ carp = _should_carp_about_exclusion(reason)
+
def decorate(fn):
fn_name = fn.__name__
def maybe(*args, **kw):
if predicate():
msg = "'%s' skipped on DB %s version '%s': %s" % (
fn_name, config.db.name, _server_version(), reason)
- raise SkipTest(msg)
+ print msg
+ if carp:
+ print >> sys.stderr, msg
+ return True
else:
return fn(*args, **kw)
return function_named(maybe, fn_name)
class SQLSoupTest(TestBase):
- __skip_if__ = (lambda: not SQLSoupTest._has_sqlite(),)
+ __requires__ = ('sqlite', )
- @classmethod
- def _has_sqlite(cls):
- try:
- import sqlite3
- except ImportError:
- try:
- import pysqlite2
- except ImportError:
- return False
- return True
-
@classmethod
def setup_class(cls):
global engine
class UnpickleSA05Test(_fixtures.FixtureTest):
"""test loading picklestrings from SQLA 0.5."""
+ __requires__ = ('python2',)
+
@testing.resolve_artifact_names
def test_one(self):
mapper(User, users, properties={