]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Support pytest 6.x
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 27 Sep 2020 01:01:01 +0000 (21:01 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 27 Sep 2020 01:12:01 +0000 (21:12 -0400)
pytest has removed support for pytest.Class().collect()
and we need to use from_parent.

Change-Id: Ia5fed9b22e76c99f71489283acee207f996f52a4
(cherry picked from commit ffafbd4b9657a4ee8bec57c0861414144f37bdc5)

lib/sqlalchemy/testing/plugin/pytestplugin.py

index 079066d82953b1b192a8b7151de1bc3d12309033..ad4ebb656553b2279e52fa68840baad341ea8e8a 100644 (file)
@@ -162,13 +162,10 @@ def pytest_collection_modifyitems(session, config, items):
             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)
@@ -196,15 +193,11 @@ def pytest_pycollect_makeitem(collector, name, obj):
 
     if inspect.isclass(obj) and plugin_base.want_class(name, obj):
 
-        # in pytest 5.4.0
-        # return [
-        #     pytest.Class.from_parent(collector,
-        # name=parametrize_cls.__name__)
-        #     for parametrize_cls in _parametrize_cls(collector.module, obj)
-        # ]
+        # support pytest 5.4.0 and above pytest.Class.from_parent
+        ctor = getattr(pytest.Class, "from_parent", pytest.Class)
 
         return [
-            pytest.Class(parametrize_cls.__name__, parent=collector)
+            ctor(name=parametrize_cls.__name__, parent=collector)
             for parametrize_cls in _parametrize_cls(collector.module, obj)
         ]
     elif (