pytest-lambda icon indicating copy to clipboard operation
pytest-lambda copied to clipboard

Fails with pytest >= 8.4

Open eldjh3 opened this issue 7 months ago • 1 comments

This is due to internal changes in pytest introduced in https://github.com/pytest-dev/pytest/pull/12473. The representation of a fixture is changed to a class FixtureFunctionDefinition rather than a simple callable. A check is added in _pytest/fixtures.py (FixtureManager.parsefactories) during fixture registration that ensures a fixture is derived from this type. As this is not the case for fixtures generated by pytest-lambda they fail to be registered.

Tests fail as a result with missing fixture errors.

        for name in dir(holderobj):
            # The attribute can be an arbitrary descriptor, so the attribute
            # access below can raise. safe_getattr() ignores such exceptions.
            obj_ub = safe_getattr(holderobj_tp, name, None)
            if type(obj_ub) is FixtureFunctionDefinition:                           # <-- Additional check
                marker = obj_ub._fixture_function_marker
                if marker.name:
                    fixture_name = marker.name
                else:
                    fixture_name = name

                # OK we know it is a fixture -- now safe to look up on the _instance_.
                try:
                    obj = getattr(holderobj, name)
                # if the fixture is named in the decorator we cannot find it in the module
                except AttributeError:
                    obj = obj_ub

                func = obj._get_wrapped_function()

                self._register_fixture(
                    name=fixture_name,
                    nodeid=nodeid,
                    func=func,
                    scope=marker.scope,
                    params=marker.params,
                    ids=marker.ids,
                    autouse=marker.autouse,
                )

The new type is internal and is not exposed in the pytest namespace. As part of the change, the internal _PytestWrapper type has been removed too.

eldjh3 avatar Jun 20 '25 06:06 eldjh3

I can confirm that. My lambda fixtures stopped working after pytest upgrade to version >=8.4

osminogin avatar Jul 24 '25 08:07 osminogin