Support pytest 6.x

pytest has removed support for pytest.Class().collect()
and we need to use from_parent.

Change-Id: Ia5fed9b22e76c99f71489283acee207f996f52a4
This commit is contained in:
Mike Bayer
2020-09-27 11:33:26 -04:00
parent b30e9e26be
commit f0930898e0
@@ -124,8 +124,9 @@ def pytest_collection_modifyitems(session, config, items):
if sub_cls is not test_class.cls:
list_ = rebuilt_items[test_class.cls]
for inst in pytest.Class(
sub_cls.__name__,
ctor = getattr(pytest.Class, "from_parent", pytest.Class)
for inst in ctor(
name=sub_cls.__name__,
parent=test_class.parent.parent).collect():
list_.extend(inst.collect())
@@ -148,7 +149,8 @@ def pytest_collection_modifyitems(session, config, items):
def pytest_pycollect_makeitem(collector, name, obj):
if inspect.isclass(obj) and plugin_base.want_class(obj):
return pytest.Class(name, parent=collector)
ctor = getattr(pytest.Class, "from_parent", pytest.Class)
return ctor(name=name, parent=collector)
elif inspect.isfunction(obj) and \
isinstance(collector, pytest.Instance) and \
plugin_base.want_method(collector.cls, obj):