python-pytest-cases icon indicating copy to clipboard operation
python-pytest-cases copied to clipboard

@fixture incompatible with pytest 8.0.0

Open jayqi opened this issue 1 year ago • 3 comments
trafficstars

pytest 8.0.0 just released earlier today, and it looks like there's an incompatibility with pytest_cases.fixture.

Minimal example:

from pytest_cases import fixture


@fixture
def a():
    return "a"


def test_a(a):
    assert a == "a"

pytest 7.4.4, pytest-cases 3.8.2, Python 3.11.7 — Passes ✅

pytest 8.0.0, pytest-cases 3.8.2, Python 3.11.7 — Fails ❌

Traceback:

.venv/lib/python3.11/site-packages/_pytest/nodes.py:152: in _create
    return super().__call__(*k, **kw)
.venv/lib/python3.11/site-packages/_pytest/python.py:1801: in __init__
    fixtureinfo = fm.getfixtureinfo(self, self.obj, self.cls)
.venv/lib/python3.11/site-packages/_pytest/fixtures.py:1490: in getfixtureinfo
    names_closure, arg2fixturedefs = self.getfixtureclosure(
E   TypeError: getfixtureclosure() got an unexpected keyword argument 'initialnames'

During handling of the above exception, another exception occurred:
.venv/lib/python3.11/site-packages/pluggy/_hooks.py:501: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
.venv/lib/python3.11/site-packages/pluggy/_manager.py:119: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
.venv/lib/python3.11/site-packages/_pytest/python.py:277: in pytest_pycollect_makeitem
    return list(collector._genfunctions(name, obj))
.venv/lib/python3.11/site-packages/_pytest/python.py:486: in _genfunctions
    definition: FunctionDefinition = FunctionDefinition.from_parent(
.venv/lib/python3.11/site-packages/_pytest/python.py:1809: in from_parent
    return super().from_parent(parent=parent, **kw)
.venv/lib/python3.11/site-packages/_pytest/nodes.py:275: in from_parent
    return cls._create(parent=parent, **kw)
.venv/lib/python3.11/site-packages/_pytest/nodes.py:167: in _create
    return super().__call__(*k, **known_kw)
.venv/lib/python3.11/site-packages/_pytest/python.py:1801: in __init__
    fixtureinfo = fm.getfixtureinfo(self, self.obj, self.cls)
.venv/lib/python3.11/site-packages/_pytest/fixtures.py:1490: in getfixtureinfo
    names_closure, arg2fixturedefs = self.getfixtureclosure(
E   TypeError: getfixtureclosure() got an unexpected keyword argument 'initialnames'

jayqi avatar Jan 28 '24 02:01 jayqi

I can confirm the issue.

kdeldycke avatar Jan 31 '24 13:01 kdeldycke

Issue stems from this commit: https://github.com/pytest-dev/pytest/commit/385796ba494e7ae65d55892d4a358b371ac7a6b6

Running the example on the commit just before works fine. After this commit, I get the reported error.

connesy avatar Feb 02 '24 22:02 connesy

Thanks a lot for reporting @jayqi ! For now inded the workaround is to use pytest<8. I'll have a look in the upcoming weeks

Note: another user also mentioned that the symptom could be

AttributeError: 'MiniMetaFunc' object has no attribute `_arg2fixturedefs`

smarie avatar Feb 07 '24 12:02 smarie