From c9a1e570ad68028e0de0551155caeae313c9c7fd Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 22 Jan 2012 13:19:22 -0500 Subject: [PATCH] - rework the test suite to make use of SkipTest for tests skipped, unsupported, etc. so that we can get an accurate picture what's really running/not, what's installed on jenkins, etc. Tested in cpython 2.7 so far, we'll see what jenkins says about other platforms --- test/bootstrap/noseplugin.py | 61 +++++++++++++-------------- test/lib/requires.py | 2 +- test/lib/testing.py | 20 ++------- test/orm/inheritance/test_magazine.py | 4 +- test/orm/test_unitofwork.py | 7 +-- 5 files changed, 38 insertions(+), 56 deletions(-) diff --git a/test/bootstrap/noseplugin.py b/test/bootstrap/noseplugin.py index 9cdfcee0e5..c9e85c8dc5 100644 --- a/test/bootstrap/noseplugin.py +++ b/test/bootstrap/noseplugin.py @@ -9,7 +9,7 @@ import StringIO import nose.case from nose.plugins import Plugin - +from nose import SkipTest from test.bootstrap import config from test.bootstrap.config import ( @@ -125,49 +125,54 @@ class NoseSQLAlchemy(Plugin): if not issubclass(cls, fixtures.TestBase): return False else: - if (hasattr(cls, '__whitelist__') and testing.db.name in cls.__whitelist__): - return True + if hasattr(cls, 'setup_class'): + existing_setup = cls.setup_class.im_func else: - return not self.__should_skip_for(cls) + existing_setup = None + @classmethod + def setup_class(cls): + self._do_skips(cls) + if existing_setup: + existing_setup(cls) + cls.setup_class = setup_class + + return True - def __should_skip_for(self, cls): + def _do_skips(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': - # The requirement will perform messaging. - return True + check(test_suite)() if cls.__unsupported_on__: spec = testing.db_spec(*cls.__unsupported_on__) if spec(testing.db): - print "'%s' unsupported on DB implementation '%s'" % ( - cls.__class__.__name__, testing.db.name) - return True + raise SkipTest( + "'%s' unsupported on DB implementation '%s'" % ( + cls.__name__, testing.db.name) + ) if getattr(cls, '__only_on__', None): spec = testing.db_spec(*util.to_list(cls.__only_on__)) if not spec(testing.db): - print "'%s' unsupported on DB implementation '%s'" % ( - cls.__class__.__name__, testing.db.name) - return True + raise SkipTest( + "'%s' unsupported on DB implementation '%s'" % ( + cls.__name__, testing.db.name) + ) if getattr(cls, '__skip_if__', False): for c in getattr(cls, '__skip_if__'): if c(): - 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" % ( - cls.__class__.__name__, testing.db.name, - _server_version()) - return True - return False + raise SkipTest("'%s' skipped by %s" % ( + cls.__name__, c.__name__) + ) + + for db, op, spec in getattr(cls, '__excluded_on__', ()): + testing.exclude(db, op, spec, "'%s' unsupported on DB %s version %s" % ( + cls.__name__, testing.db.name, + testing._server_version())) def beforeTest(self, test): testing.resetwarnings() @@ -180,9 +185,3 @@ class NoseSQLAlchemy(Plugin): engines.testing_reaper._stop_test_ctx() if not config.options.low_connections: testing.global_cleanup_assertions() - - #def handleError(self, test, err): - #pass - - #def finalize(self, result=None): - #pass diff --git a/test/lib/requires.py b/test/lib/requires.py index 65ad0aa8f5..89b9a317b0 100644 --- a/test/lib/requires.py +++ b/test/lib/requires.py @@ -20,7 +20,7 @@ from test.lib import config import testing import sys -def deferrable_constraints(fn): +def deferrable_or_no_constraints(fn): """Target database must support derferable constraints.""" return _chain_decorators_on( fn, diff --git a/test/lib/testing.py b/test/lib/testing.py index 53a277b9df..1d00d04d88 100644 --- a/test/lib/testing.py +++ b/test/lib/testing.py @@ -188,10 +188,7 @@ def _block_unconditionally(db, reason): if spec(config.db): msg = "'%s' unsupported on DB implementation '%s+%s': %s" % ( fn.__name__, config.db.name, config.db.driver, reason) - print msg - if carp: - print >> sys.stderr, msg - return True + raise SkipTest(msg) else: return fn(*args, **kw) return decorate @@ -206,10 +203,7 @@ def only_on(dbs, reason): else: msg = "'%s' unsupported on DB implementation '%s+%s': %s" % ( fn.__name__, config.db.name, config.db.driver, reason) - print msg - if carp: - print >> sys.stderr, msg - return True + raise SkipTest(msg) return decorate def exclude(db, op, spec, reason): @@ -231,10 +225,7 @@ def exclude(db, op, spec, reason): if _is_excluded(db, op, spec): msg = "'%s' unsupported on DB %s version '%s': %s" % ( fn.__name__, config.db.name, _server_version(), reason) - print msg - if carp: - print >> sys.stderr, msg - return True + raise SkipTest(msg) else: return fn(*args, **kw) return decorate @@ -300,10 +291,7 @@ def skip_if(predicate, reason=None): if predicate(): msg = "'%s' skipped on DB %s version '%s': %s" % ( fn.__name__, config.db.name, _server_version(), reason) - print msg - if carp: - print >> sys.stderr, msg - return True + raise SkipTest(msg) else: return fn(*args, **kw) return decorate diff --git a/test/orm/inheritance/test_magazine.py b/test/orm/inheritance/test_magazine.py index 70387477f6..840270e589 100644 --- a/test/orm/inheritance/test_magazine.py +++ b/test/orm/inheritance/test_magazine.py @@ -121,7 +121,7 @@ class MagazineTest(fixtures.MappedTest): Column('name', String(45), default=''), ) -def generate_round_trip_test(use_unions=False, use_joins=False): +def _generate_round_trip_test(use_unions=False, use_joins=False): def test_roundtrip(self): publication_mapper = mapper(Publication, publication_table) @@ -216,6 +216,6 @@ def generate_round_trip_test(use_unions=False, use_joins=False): setattr(MagazineTest, test_roundtrip.__name__, test_roundtrip) for (use_union, use_join) in [(True, False), (False, True), (False, False)]: - generate_round_trip_test(use_union, use_join) + _generate_round_trip_test(use_union, use_join) diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index be781109d2..362ff35ca1 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -2359,12 +2359,7 @@ class InheritingRowSwitchTest(fixtures.MappedTest): ) class TransactionTest(fixtures.MappedTest): - __requires__ = ('deferrable_constraints',) - - __whitelist__ = ('sqlite',) - # sqlite doesn't have deferrable constraints, but it allows them to - # be specified. it'll raise immediately post-INSERT, instead of at - # COMMIT. either way, this test should pass. + __requires__ = ('deferrable_or_no_constraints',) @classmethod def define_tables(cls, metadata): -- 2.47.2