diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-12 23:44:42 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-13 17:05:08 -0400 |
commit | dfd20fbbdb3cbbb6e74df2ecf1af236d6e067a59 (patch) | |
tree | 718e82e2626de57bd6fd4df0abe5237d2240a40a /lib/sqlalchemy/testing/plugin/pytestplugin.py | |
parent | 17413bbf10c3b993d343c28035713a23c745712c (diff) | |
download | sqlalchemy-dfd20fbbdb3cbbb6e74df2ecf1af236d6e067a59.tar.gz |
Use pytest items in custom collection
We have a custom test collection hook that did not take
node of the actual list of functions in items. By looking
in this list we now support the class/function arguments
passed to the py.test command line.
Change-Id: I1238c7c5796a296037ab9ef3bedf0f619a730481
Diffstat (limited to 'lib/sqlalchemy/testing/plugin/pytestplugin.py')
-rw-r--r-- | lib/sqlalchemy/testing/plugin/pytestplugin.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py index f42fc4791..99106d7e5 100644 --- a/lib/sqlalchemy/testing/plugin/pytestplugin.py +++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py @@ -129,31 +129,35 @@ def pytest_collection_modifyitems(session, config, items): # 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) + rebuilt_items = collections.defaultdict( + lambda: collections.defaultdict(list) + ) items[:] = [ item for item in items if isinstance(item.parent, pytest.Instance) and not item.parent.parent.name.startswith("_") ] + 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: - list_ = rebuilt_items[test_class.cls] + per_cls_dict = rebuilt_items[test_class.cls] + names = [i.name for i in items] for inst in pytest.Class( sub_cls.__name__, parent=test_class.parent.parent ).collect(): - list_.extend(inst.collect()) + for t in inst.collect(): + per_cls_dict[t.name].append(t) newitems = [] for item in items: if item.parent.cls in rebuilt_items: - newitems.extend(rebuilt_items[item.parent.cls]) - rebuilt_items[item.parent.cls][:] = [] + newitems.extend(rebuilt_items[item.parent.cls][item.name]) else: newitems.append(item) |