From ed553fffd65a063d6dbdb3770d1fa0124bd55e23 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 17 Oct 2019 13:09:24 -0400 Subject: 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 --- lib/sqlalchemy/testing/plugin/plugin_base.py | 50 +++++++++++++++++++++------- 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'lib/sqlalchemy/testing/plugin/plugin_base.py') 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 -- cgit v1.2.1