diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-10-17 13:09:24 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-10-20 20:49:03 -0400 |
| commit | ed553fffd65a063d6dbdb3770d1fa0124bd55e23 (patch) | |
| tree | 59ab8a457b3ed82cb7647b7da1b94b4ce2a815e1 /lib/sqlalchemy/testing/config.py | |
| parent | 528782d1c356445f17cea857ef0974e074c51d60 (diff) | |
| download | sqlalchemy-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/config.py')
| -rw-r--r-- | lib/sqlalchemy/testing/config.py | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/lib/sqlalchemy/testing/config.py b/lib/sqlalchemy/testing/config.py index f94c5b308..87bbc6a0f 100644 --- a/lib/sqlalchemy/testing/config.py +++ b/lib/sqlalchemy/testing/config.py @@ -6,7 +6,6 @@ # the MIT License: http://www.opensource.org/licenses/mit-license.php import collections -from unittest import SkipTest as _skip_test_exception requirements = None db = None @@ -17,6 +16,75 @@ test_schema = None test_schema_2 = None _current = None +_fixture_functions = None # installed by plugin_base + + +def combinations(*comb, **kw): + r"""Deliver multiple versions of a test based on positional combinations. + + This is a facade over pytest.mark.parametrize. + + + :param \*comb: argument combinations. These are tuples that will be passed + positionally to the decorated function. + + :param argnames: optional list of argument names. These are the names + of the arguments in the test function that correspond to the entries + in each argument tuple. pytest.mark.parametrize requires this, however + the combinations function will derive it automatically if not present + by using ``inspect.getfullargspec(fn).args[1:]``. Note this assumes the + first argument is "self" which is discarded. + + :param id\_: optional id template. This is a string template that + describes how the "id" for each parameter set should be defined, if any. + The number of characters in the template should match the number of + entries in each argument tuple. Each character describes how the + corresponding entry in the argument tuple should be handled, as far as + whether or not it is included in the arguments passed to the function, as + well as if it is included in the tokens used to create the id of the + parameter set. + + If omitted, the argment combinations are passed to parametrize as is. If + passed, each argument combination is turned into a pytest.param() object, + mapping the elements of the argument tuple to produce an id based on a + character value in the same position within the string template using the + following scheme:: + + i - the given argument is a string that is part of the id only, don't + pass it as an argument + + n - the given argument should be passed and it should be added to the + id by calling the .__name__ attribute + + r - the given argument should be passed and it should be added to the + id by calling repr() + + s- the given argument should be passed and it should be added to the + id by calling str() + + e.g.:: + + @testing.combinations( + (operator.eq, "eq"), + (operator.ne, "ne"), + (operator.gt, "gt"), + (operator.lt, "lt"), + id_="na" + ) + def test_operator(self, opfunc, name): + pass + + The above combination will call ``.__name__`` on the first member of + each tuple and use that as the "id" to pytest.param(). + + + """ + return _fixture_functions.combinations(*comb, **kw) + + +def fixture(*arg, **kw): + return _fixture_functions.fixture(*arg, **kw) + class Config(object): def __init__(self, db, db_opts, options, file_config): @@ -94,4 +162,4 @@ class Config(object): def skip_test(msg): - raise _skip_test_exception(msg) + raise _fixture_functions.skip_test_exception(msg) |
