pytest 4.6.3 compatibility

Issue #29 new
Angus Gibson created an issue

I’m not sure the exact version requirements for this, but using pytest 4.6.3 I get some major errors running the test suite. Apologies if this isn’t intended to be a supported version (I am very new to this project).

In test/unit/test_quadrature.py:

________________ ERROR collecting test/unit/test_quadrature.py _________________
Fixture "interval" called directly. Fixtures are not meant to be called directly,
but are created automatically when test functions request them as parameters.
See https://docs.pytest.org/en/latest/fixture.html for more information about fixtures, and
https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly about how to update your code.

It may be possible to restructure this test to not parametrize over fixtures, but a simple fix is to add the pytest-lazy-fixture module, and make the following code change:

diff --git a/../nix-build-python3.7-fiat-2019.1.0.drv-0/fiat-2019.1.0/test/unit/test_quadrature.py b/./test/unit/tes
t_quadrature.py
index 68c5c7e..134e908 100644
--- a/../nix-build-python3.7-fiat-2019.1.0.drv-0/fiat-2019.1.0/test/unit/test_quadrature.py
+++ b/./test/unit/test_quadrature.py
@@ -134,18 +134,18 @@ def test_create_quadrature_extr_quadrilateral(extr_quadrilateral, basedeg, extrd
                           (2**(basedeg + 2) - 2) / ((basedeg + 1)*(basedeg + 2)) * 1/(extrdeg + 1))


-@pytest.mark.parametrize("cell", [interval(),
-                                  triangle(),
-                                  tetrahedron(),
-                                  quadrilateral()])
+@pytest.mark.parametrize("cell", [pytest.lazy_fixture('interval'),
+                                  pytest.lazy_fixture('triangle'),
+                                  pytest.lazy_fixture('tetrahedron'),
+                                  pytest.lazy_fixture('quadrilateral')])
 def test_invalid_quadrature_degree(cell, scheme):
     with pytest.raises(ValueError):
         FIAT.create_quadrature(cell, -1, scheme)


-@pytest.mark.parametrize("cell", [extr_interval(),
-                                  extr_triangle(),
-                                  extr_quadrilateral()])
+@pytest.mark.parametrize("cell", [pytest.lazy_fixture('extr_interval'),
+                                  pytest.lazy_fixture('extr_triangle'),
+                                  pytest.lazy_fixture('extr_quadrilateral')])
 def test_invalid_quadrature_degree_tensor_prod(cell):
     with pytest.raises(ValueError):
         FIAT.create_quadrature(cell, (-1, -1))

And the more cryptic error in test/unit/test_reference_element.py:

_____________ ERROR collecting test/unit/test_reference_element.py _____________
/nix/store/ma1mczcg2x639dqiax99bda1g83nvw04-python3.7-pluggy-0.12.0/lib/python3.7/site-packages/pluggy/hooks.py:289:
    return self._hookexec(self, self.get_hookimpls(), kwargs)
/nix/store/ma1mczcg2x639dqiax99bda1g83nvw04-python3.7-pluggy-0.12.0/lib/python3.7/site-packages/pluggy/manager.py:87
    return self._inner_hookexec(hook, methods, kwargs)
/nix/store/ma1mczcg2x639dqiax99bda1g83nvw04-python3.7-pluggy-0.12.0/lib/python3.7/site-packages/pluggy/manager.py:81
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
/nix/store/cmw8csqzswnl9x8yg61m5ybkskv553h7-python3.7-pytest-4.6.3/lib/python3.7/site-packages/_pytest/python.py:234
    res = list(collector._genfunctions(name, obj))
/nix/store/cmw8csqzswnl9x8yg61m5ybkskv553h7-python3.7-pytest-4.6.3/lib/python3.7/site-packages/_pytest/python.py:410
    self.ihook.pytest_generate_tests(metafunc=metafunc)
/nix/store/ma1mczcg2x639dqiax99bda1g83nvw04-python3.7-pluggy-0.12.0/lib/python3.7/site-packages/pluggy/hooks.py:289:
    return self._hookexec(self, self.get_hookimpls(), kwargs)
/nix/store/ma1mczcg2x639dqiax99bda1g83nvw04-python3.7-pluggy-0.12.0/lib/python3.7/site-packages/pluggy/manager.py:87
    return self._inner_hookexec(hook, methods, kwargs)
/nix/store/ma1mczcg2x639dqiax99bda1g83nvw04-python3.7-pluggy-0.12.0/lib/python3.7/site-packages/pluggy/manager.py:81
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
/nix/store/cmw8csqzswnl9x8yg61m5ybkskv553h7-python3.7-pytest-4.6.3/lib/python3.7/site-packages/_pytest/python.py:137
    metafunc.parametrize(*marker.args, **marker.kwargs)
/nix/store/cmw8csqzswnl9x8yg61m5ybkskv553h7-python3.7-pytest-4.6.3/lib/python3.7/site-packages/_pytest/python.py:100
    function_definition=self.definition,
/nix/store/cmw8csqzswnl9x8yg61m5ybkskv553h7-python3.7-pytest-4.6.3/lib/python3.7/site-packages/_pytest/mark/structur
    if len(param.values) != len(argnames):
E   TypeError: object of type 'MarkDecorator' has no len()

This is down to the use of pytest.mark.xfail in the parametrize lists. The following patch fixes this for me:

diff --git a/../nix-build-python3.7-fiat-2019.1.0.drv-0/fiat-2019.1.0/test/unit/test_reference_element.py b/./test/u
nit/test_reference_element.py
index edc1fea..a509b6c 100644
--- a/../nix-build-python3.7-fiat-2019.1.0.drv-0/fiat-2019.1.0/test/unit/test_reference_element.py
+++ b/./test/unit/test_reference_element.py
@@ -39,8 +39,8 @@ ufc_hexahedron_21connectivity = [(0, 1, 4, 5), (2, 3, 6, 7), (0, 2, 8, 9),
 @pytest.mark.parametrize(('cell', 'connectivity'),
                          [(tetrahedron, ufc_tetrahedron_21connectivity),
                           (hexahedron, ufc_hexahedron_21connectivity),
-                          pytest.mark.xfail((triangle_x_interval, [])),
-                          pytest.mark.xfail((quadrilateral_x_interval, []))])
+                          pytest.param(triangle_x_interval, [], marks=pytest.mark.xfail),
+                          pytest.param(quadrilateral_x_interval, [], marks=pytest.mark.xfail)])
 def test_ufc_connectivity_21(cell, connectivity):
     """Check face-edge connectivity builds what UFC expects.
     This is only non-trivial case ; the rest is x-0 and D-x,
@@ -51,9 +51,9 @@ def test_ufc_connectivity_21(cell, connectivity):
 @pytest.mark.parametrize('cell',
                          [point, interval, triangle, tetrahedron,
                           quadrilateral, hexahedron,
-                          pytest.mark.xfail(interval_x_interval),
-                          pytest.mark.xfail(triangle_x_interval),
-                          pytest.mark.xfail(quadrilateral_x_interval)])
+                          pytest.param(interval_x_interval, marks=pytest.mark.xfail),
+                          pytest.param(triangle_x_interval, marks=pytest.mark.xfail),
+                          pytest.param(quadrilateral_x_interval, marks=pytest.mark.xfail)])
 def test_ufc_connectivity_x0(cell):
     """Check x-0 connectivity is just what get_topology gives"""
     for dim0 in range(cell.get_spatial_dimension()+1):
@@ -66,9 +66,9 @@ def test_ufc_connectivity_x0(cell):
 @pytest.mark.parametrize('cell',
                          [point, interval, triangle, tetrahedron,
                           quadrilateral, hexahedron,
-                          pytest.mark.xfail(interval_x_interval),
-                          pytest.mark.xfail(triangle_x_interval),
-                          pytest.mark.xfail(quadrilateral_x_interval)])
+                          pytest.param(interval_x_interval, marks=pytest.mark.xfail),
+                          pytest.param(triangle_x_interval, marks=pytest.mark.xfail),
+                          pytest.param(quadrilateral_x_interval, marks=pytest.mark.xfail)])
 def test_ufc_connectivity_Dx(cell):
     """Check D-x connectivity is just [(0,1,2,...)]"""
     D = cell.get_spatial_dimension()
@@ -79,7 +79,7 @@ def test_ufc_connectivity_Dx(cell):


 @pytest.mark.parametrize(('cell', 'volume'),
-                         [pytest.mark.xfail((point, 1)),
+                         [pytest.param(point, 1, marks=pytest.mark.xfail),
                           (interval, 1),
                           (triangle, 1/2),
                           (quadrilateral, 1),

Comments (1)

  1. Log in to comment