summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/plugin/plugin_base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-10-17 13:09:24 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-10-20 20:49:03 -0400
commited553fffd65a063d6dbdb3770d1fa0124bd55e23 (patch)
tree59ab8a457b3ed82cb7647b7da1b94b4ce2a815e1 /lib/sqlalchemy/testing/plugin/plugin_base.py
parent528782d1c356445f17cea857ef0974e074c51d60 (diff)
downloadsqlalchemy-ed553fffd65a063d6dbdb3770d1fa0124bd55e23.tar.gz
Implement facade for pytest parametrize, fixtures, classlevel
Add factilities to implement pytest.mark.parametrize and pytest.fixtures patterns, which largely resemble things we are already doing. Ensure a facade is used, so that the test suite remains independent of py.test, but also tailors the functions to the more limited scope in which we are using them. Additionally, create a class-based version that works from the same facade. Several old polymorphic tests as well as two of the sql test are refactored to use the new features. Change-Id: I6ef8af1dafff92534313016944d447f9439856cf References: #4896
Diffstat (limited to 'lib/sqlalchemy/testing/plugin/plugin_base.py')
-rw-r--r--lib/sqlalchemy/testing/plugin/plugin_base.py50
1 files changed, 38 insertions, 12 deletions
diff --git a/lib/sqlalchemy/testing/plugin/plugin_base.py b/lib/sqlalchemy/testing/plugin/plugin_base.py
index 859d1d779..a2f969a66 100644
--- a/lib/sqlalchemy/testing/plugin/plugin_base.py
+++ b/lib/sqlalchemy/testing/plugin/plugin_base.py
@@ -16,6 +16,7 @@ is py.test.
from __future__ import absolute_import
+import abc
import re
import sys
@@ -24,8 +25,15 @@ py3k = sys.version_info >= (3, 0)
if py3k:
import configparser
+
+ ABC = abc.ABC
else:
import ConfigParser as configparser
+ import collections as collections_abc # noqa
+
+ class ABC(object):
+ __metaclass__ = abc.ABCMeta
+
# late imports
fixtures = None
@@ -238,14 +246,6 @@ def set_coverage_flag(value):
options.has_coverage = value
-_skip_test_exception = None
-
-
-def set_skip_test(exc):
- global _skip_test_exception
- _skip_test_exception = exc
-
-
def post_begin():
"""things to set up later, once we know coverage is running."""
# Lazy setup of other options (post coverage)
@@ -331,10 +331,10 @@ def _monkeypatch_cdecimal(options, file_config):
@post
-def _init_skiptest(options, file_config):
+def _init_symbols(options, file_config):
from sqlalchemy.testing import config
- config._skip_test_exception = _skip_test_exception
+ config._fixture_functions = _fixture_fn_class()
@post
@@ -486,10 +486,10 @@ def _setup_profiling(options, file_config):
)
-def want_class(cls):
+def want_class(name, cls):
if not issubclass(cls, fixtures.TestBase):
return False
- elif cls.__name__.startswith("_"):
+ elif name.startswith("_"):
return False
elif (
config.options.backend_only
@@ -711,3 +711,29 @@ def _do_skips(cls):
def _setup_config(config_obj, ctx):
config._current.push(config_obj, testing)
+
+
+class FixtureFunctions(ABC):
+ @abc.abstractmethod
+ def skip_test_exception(self, *arg, **kw):
+ raise NotImplementedError()
+
+ @abc.abstractmethod
+ def combinations(self, *args, **kw):
+ raise NotImplementedError()
+
+ @abc.abstractmethod
+ def param_ident(self, *args, **kw):
+ raise NotImplementedError()
+
+ @abc.abstractmethod
+ def fixture(self, fn):
+ raise NotImplementedError()
+
+
+_fixture_fn_class = None
+
+
+def set_fixture_functions(fixture_fn_class):
+ global _fixture_fn_class
+ _fixture_fn_class = fixture_fn_class