summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-03-03 13:27:32 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-03-03 13:27:32 -0500
commita203233a1196496499c1518242dcafd95d297796 (patch)
tree74faa57d233d3688423e48964c60f7427e39af55
parenta342e554756208ad008adedfc3f7493b930f96f7 (diff)
downloadsqlalchemy-a203233a1196496499c1518242dcafd95d297796.tar.gz
- transfer to non-unittest usage. a little more tricky.
-rw-r--r--lib/sqlalchemy/testing/fixtures.py18
-rw-r--r--lib/sqlalchemy/testing/plugin/pytestplugin.py54
-rw-r--r--lib/sqlalchemy/testing/suite/test_insert.py2
-rw-r--r--test/sql/test_functions.py2
4 files changed, 44 insertions, 32 deletions
diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py
index ffe21974f..7941bf0f8 100644
--- a/lib/sqlalchemy/testing/fixtures.py
+++ b/lib/sqlalchemy/testing/fixtures.py
@@ -14,9 +14,10 @@ import sys
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base, DeclarativeMeta
-import unittest
+# whether or not we use unittest changes things dramatically,
+# as far as how py.test collection works.
-class TestBase(unittest.TestCase):
+class TestBase(object):
# A sequence of database names to always run, regardless of the
# constraints below.
__whitelist__ = ()
@@ -38,13 +39,14 @@ class TestBase(unittest.TestCase):
def assert_(self, val, msg=None):
assert val, msg
- def tearDown(self):
- if hasattr(self, "teardown"):
- self.teardown()
+ # apparently a handful of tests are doing this....OK
+ def setup(self):
+ if hasattr(self, "setUp"):
+ self.setUp()
- def setUp(self):
- if hasattr(self, "setup"):
- self.setup()
+ def teardown(self):
+ if hasattr(self, "tearDown"):
+ self.tearDown()
class TablesTest(TestBase):
diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py
index 8a39b043a..841029751 100644
--- a/lib/sqlalchemy/testing/plugin/pytestplugin.py
+++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py
@@ -3,8 +3,6 @@ import argparse
import inspect
from . import plugin_base
-py_unittest = None
-
def pytest_addoption(parser):
group = parser.getgroup("sqlalchemy")
@@ -28,9 +26,6 @@ def pytest_configure(config):
plugin_base.post_begin()
- # because it feels icky importing from "_pytest"..
- global py_unittest
- py_unittest = config.pluginmanager.getplugin('unittest')
import collections
def pytest_collection_modifyitems(session, config, items):
@@ -38,20 +33,22 @@ def pytest_collection_modifyitems(session, config, items):
# expand them out into per-database test cases.
# this is much easier to do within pytest_pycollect_makeitem, however
- # pytest is unfortunately iterating through cls.__dict__ as makeitem is
+ # pytest is iterating through cls.__dict__ as makeitem is
# called which causes a "dictionary changed size" error on py3k.
# I'd submit a pullreq for them to turn it into a list first, but
# it's to suit the rather odd use case here which is that we are adding
# new classes to a module on the fly.
rebuilt_items = collections.defaultdict(list)
-
test_classes = set(item.parent for item in items)
for test_class in test_classes:
for sub_cls in plugin_base.generate_sub_tests(test_class.cls, test_class.parent.module):
if sub_cls is not test_class.cls:
- rebuilt_items[test_class.cls].extend(py_unittest.UnitTestCase(
- sub_cls.__name__, parent=test_class.parent).collect())
+ list_ = rebuilt_items[test_class.cls]
+
+ for inst in pytest.Class(sub_cls.__name__,
+ parent=test_class.parent.parent).collect():
+ list_.extend(inst.collect())
newitems = []
for item in items:
@@ -61,36 +58,49 @@ def pytest_collection_modifyitems(session, config, items):
else:
newitems.append(item)
- items[:] = newitems
+ # seems like the functions attached to a test class aren't sorted already?
+ # is that true and why's that? (when using unittest, they're sorted)
+ items[:] = sorted(newitems, key=lambda item: (
+ item.parent.parent.parent.name,
+ item.parent.parent.name,
+ item.name
+ )
+ )
+
def pytest_pycollect_makeitem(collector, name, obj):
+ # how come if I catch "Module" objects here directly
+ # and return [] for those I don't want,
+ # that doesn't seem to change the results? I need to filter
+ # modules after I get the individual functions...
+
if inspect.isclass(obj) and plugin_base.want_class(obj):
- return py_unittest.UnitTestCase(name, parent=collector)
+ return pytest.Class(name, parent=collector)
+ elif inspect.isfunction(obj) and \
+ name.startswith("test_") and \
+ isinstance(collector, pytest.Instance):
+ return pytest.Function(name, parent=collector)
else:
return []
_current_class = None
def pytest_runtest_setup(item):
- # I'd like to get module/class/test level calls here
- # but I don't quite see the pattern.
-
- # not really sure what determines if we're called
- # here with pytest.Class, pytest.Module, does not seem to be
- # consistent
-
+ # here we seem to get called only based on what we collected
+ # in pytest_collection_modifyitems. So to do class-based stuff
+ # we have to tear that out.
global _current_class
# ... so we're doing a little dance here to figure it out...
- if item.parent is not _current_class:
+ if item.parent.parent is not _current_class:
- class_setup(item.parent)
- _current_class = item.parent
+ class_setup(item.parent.parent)
+ _current_class = item.parent.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.parent.parent.addfinalizer(lambda: class_teardown(item.parent.parent))
test_setup(item)
diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py
index ce77fdd47..b6fb597dc 100644
--- a/lib/sqlalchemy/testing/suite/test_insert.py
+++ b/lib/sqlalchemy/testing/suite/test_insert.py
@@ -159,7 +159,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
)
class ReturningTest(fixtures.TablesTest):
- run_deletes = 'each'
+ run_create_tables = 'each'
__requires__ = 'returning', 'autoincrement_insert'
__multiple__ = True
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py
index 6c6d97fab..7fd7058b5 100644
--- a/test/sql/test_functions.py
+++ b/test/sql/test_functions.py
@@ -215,7 +215,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
sqltypes.DateTime)
]:
assert isinstance(fn(*args).type, type_), \
- "%s / %s" % (fn(), type_)
+ "%s / %r != %s" % (fn(), fn(*args).type, type_)
assert isinstance(func.concat("foo", "bar").type, sqltypes.String)