diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-12-04 19:18:57 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-12-04 19:18:57 -0500 |
commit | 1ab483ac5481cb60e898f0bfdad54e5ca45bbb80 (patch) | |
tree | da401d91f98b9d59035c27c0f056bf9bd83ce0a5 /lib/sqlalchemy/testing/util.py | |
parent | 380f4389922004589bfa7cb4f9b8c8208aa68659 (diff) | |
download | sqlalchemy-1ab483ac5481cb60e898f0bfdad54e5ca45bbb80.tar.gz |
Introduce lambda combinations
As the ORM's combinatoric tests mostly use entities and
table metadata that's defined in fixtures, we can't use
@testing.combinations directly as it takes place at the
module level. Instead we use lambdas, but to reduce
verbosity we use a code replacement so that the namespace
of the lambda can be provided at runtime rather than
module import time.
Change-Id: Ia63a510f9c1d08b055eef62cf047f1f427f0450c
Diffstat (limited to 'lib/sqlalchemy/testing/util.py')
-rw-r--r-- | lib/sqlalchemy/testing/util.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/sqlalchemy/testing/util.py b/lib/sqlalchemy/testing/util.py index 87c461fd2..dbe6a383d 100644 --- a/lib/sqlalchemy/testing/util.py +++ b/lib/sqlalchemy/testing/util.py @@ -261,6 +261,21 @@ def flag_combinations(*combinations): ) +def resolve_lambda(__fn, **kw): + """Given a no-arg lambda and a namespace, return a new lambda that + has all the values filled in. + + This is used so that we can have module-level fixtures that + refer to instance-level variables using lambdas. + + """ + + glb = dict(__fn.__globals__) + glb.update(kw) + new_fn = types.FunctionType(__fn.__code__, glb) + return new_fn() + + def metadata_fixture(ddl="function"): """Provide MetaData for a pytest fixture.""" |