if sub_cls is not test_class.cls:
per_cls_dict = rebuilt_items[test_class.cls]
- # in pytest 5.4.0
- # for inst in pytest.Class.from_parent(
- # test_class.parent.parent, name=sub_cls.__name__
- # ).collect():
-
- for inst in pytest.Class(
- sub_cls.__name__, parent=test_class.parent.parent
+ # support pytest 5.4.0 and above pytest.Class.from_parent
+ ctor = getattr(pytest.Class, "from_parent", pytest.Class)
+ for inst in ctor(
+ name=sub_cls.__name__, parent=test_class.parent.parent
).collect():
for t in inst.collect():
per_cls_dict[t.name].append(t)