summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-03-03 01:23:03 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-03-03 01:23:03 -0500
commit59c2f4c8d47ba991b3b1ef0727c0e742e574d3e6 (patch)
tree82314874424fc88586c9d3eaaeff9ce19a638c8b /lib/sqlalchemy
parent7aada75c4e2560088826fa5bff40415058c97beb (diff)
downloadsqlalchemy-59c2f4c8d47ba991b3b1ef0727c0e742e574d3e6.tar.gz
- fix failure cases
- get dropfirst to work around missing schemas
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/testing/exclusions.py5
-rw-r--r--lib/sqlalchemy/testing/plugin/plugin_base.py81
-rw-r--r--lib/sqlalchemy/testing/plugin/pytestplugin.py16
3 files changed, 60 insertions, 42 deletions
diff --git a/lib/sqlalchemy/testing/exclusions.py b/lib/sqlalchemy/testing/exclusions.py
index 2c642a3e8..9a713adaa 100644
--- a/lib/sqlalchemy/testing/exclusions.py
+++ b/lib/sqlalchemy/testing/exclusions.py
@@ -27,7 +27,10 @@ class skip_if(object):
@property
def enabled(self):
- return not self.predicate(config._current)
+ return self.enabled_for_config(config._current)
+
+ def enabled_for_config(self, config):
+ return not self.predicate(config)
@contextlib.contextmanager
def fail_if(self, name='block'):
diff --git a/lib/sqlalchemy/testing/plugin/plugin_base.py b/lib/sqlalchemy/testing/plugin/plugin_base.py
index 4c191f741..fd8d46e9c 100644
--- a/lib/sqlalchemy/testing/plugin/plugin_base.py
+++ b/lib/sqlalchemy/testing/plugin/plugin_base.py
@@ -86,12 +86,14 @@ def read_config():
file_config.read(['setup.cfg', 'test.cfg'])
def pre_begin(opt):
+ """things to set up early, before coverage might be setup."""
global options
options = opt
for fn in pre_configure:
fn(options, file_config)
def post_begin():
+ """things to set up later, once we know coverage is running."""
# Lazy setup of other options (post coverage)
for fn in post_configure:
fn(options, file_config)
@@ -201,14 +203,38 @@ def _engine_pool(options, file_config):
db_opts['poolclass'] = pool.AssertionPool
@post
+def _requirements(options, file_config):
+
+ requirement_cls = file_config.get('sqla_testing', "requirement_cls")
+ _setup_requirements(requirement_cls)
+
+def _setup_requirements(argument):
+ from sqlalchemy.testing import config
+ from sqlalchemy import testing
+
+ if config.requirements is not None:
+ return
+
+ modname, clsname = argument.split(":")
+
+ # importlib.import_module() only introduced in 2.7, a little
+ # late
+ mod = __import__(modname)
+ for component in modname.split(".")[1:]:
+ mod = getattr(mod, component)
+ req_cls = getattr(mod, clsname)
+
+ config.requirements = testing.requires = req_cls()
+
+@post
def _prep_testing_database(options, file_config):
from sqlalchemy.testing import config
from sqlalchemy import schema, inspect
if options.dropfirst:
- for e in config.Config.all_dbs():
+ for cfg in config.Config.all_configs():
+ e = cfg.db
inspector = inspect(e)
-
try:
view_names = inspector.get_view_names()
except NotImplementedError:
@@ -217,23 +243,25 @@ def _prep_testing_database(options, file_config):
for vname in view_names:
e.execute(schema._DropView(schema.Table(vname, schema.MetaData())))
- try:
- view_names = inspector.get_view_names(schema="test_schema")
- except NotImplementedError:
- pass
- else:
- for vname in view_names:
- e.execute(schema._DropView(
- schema.Table(vname,
- schema.MetaData(), schema="test_schema")))
+ if config.requirements.schemas.enabled_for_config(cfg):
+ try:
+ view_names = inspector.get_view_names(schema="test_schema")
+ except NotImplementedError:
+ pass
+ else:
+ for vname in view_names:
+ e.execute(schema._DropView(
+ schema.Table(vname,
+ schema.MetaData(), schema="test_schema")))
for tname in reversed(inspector.get_table_names(order_by="foreign_key")):
e.execute(schema.DropTable(schema.Table(tname, schema.MetaData())))
- for tname in reversed(inspector.get_table_names(
- order_by="foreign_key", schema="test_schema")):
- e.execute(schema.DropTable(
- schema.Table(tname, schema.MetaData(), schema="test_schema")))
+ if config.requirements.schemas.enabled_for_config(cfg):
+ for tname in reversed(inspector.get_table_names(
+ order_by="foreign_key", schema="test_schema")):
+ e.execute(schema.DropTable(
+ schema.Table(tname, schema.MetaData(), schema="test_schema")))
@post
@@ -257,29 +285,6 @@ def _reverse_topological(options, file_config):
-@post
-def _requirements(options, file_config):
-
- requirement_cls = file_config.get('sqla_testing', "requirement_cls")
- _setup_requirements(requirement_cls)
-
-def _setup_requirements(argument):
- from sqlalchemy.testing import config
- from sqlalchemy import testing
-
- if config.requirements is not None:
- return
-
- modname, clsname = argument.split(":")
-
- # importlib.import_module() only introduced in 2.7, a little
- # late
- mod = __import__(modname)
- for component in modname.split(".")[1:]:
- mod = getattr(mod, component)
- req_cls = getattr(mod, clsname)
-
- config.requirements = testing.requires = req_cls()
@post
def _post_setup_options(opt, file_config):
diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py
index 4732c62e2..735130fb4 100644
--- a/lib/sqlalchemy/testing/plugin/pytestplugin.py
+++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py
@@ -1,9 +1,10 @@
import pytest
import argparse
import inspect
-py_unittest = None
from . import plugin_base
+py_unittest = None
+
def pytest_addoption(parser):
group = parser.getgroup("sqlalchemy")
@@ -38,7 +39,6 @@ def pytest_pycollect_makeitem(collector, name, obj):
_current_class = None
-from pytest import Item
def pytest_runtest_setup(item):
# I'd like to get module/class/test level calls here
# but I don't quite see the pattern.
@@ -54,11 +54,21 @@ def pytest_runtest_setup(item):
class_setup(item.parent)
_current_class = item.parent
+
+ # this is needed for the class-level, to ensure that the
+ # teardown runs after the class is completed with its own
+ # class-level teardown...
item.parent.addfinalizer(lambda: class_teardown(item.parent))
- item.addfinalizer(lambda: test_teardown(item))
test_setup(item)
+def pytest_runtest_teardown(item):
+ # ...but this works better as the hook here rather than
+ # using a finalizer, as the finalizer seems to get in the way
+ # of the test reporting failures correctly (you get a bunch of
+ # py.test assertion stuff instead)
+ test_teardown(item)
+
def test_setup(item):
id_ = "%s.%s:%s" % (item.parent.module.__name__, item.parent.name, item.name)
plugin_base.before_test(item, id_)