pytest-lazy-fixture: Raise error with `pytest==8.0.0`

Hi! pytest-lazy-fixture doesn’t work with pytest==8.0.0

 AttributeError: 'CallSpec2' object has no attribute 'funcargs'

About this issue

  • Original URL
  • State: open
  • Created 5 months ago
  • Reactions: 48
  • Comments: 20 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Since the main branch of this repo hasn’t seen an update in two years, I’ve been looking for an alternative. In my case, I was using something like this:

# In conftest.py:
@pytest.fixture
def test_api_sqlite_mp(test_sqlite_mp):
    return Platform(_backend=RestTestBackend(test_sqlite_mp.backend))


@pytest.fixture
def test_api_pgsql_mp(test_pgsql_mp):
    return Platform(_backend=RestTestBackend(test_pgsql_mp.backend))

# In another file:
api_platforms = pytest.mark.parametrize(
    "test_mp",
    [
        pytest.lazy_fixture("test_api_sqlite_mp"),
        pytest.lazy_fixture("test_api_pgsql_mp"),
    ],
)

# And finally, for the function:
@api_platforms
def test_index_model(test_mp):
    ...

So following suggestions on StackOverflow and here, I changed that to

# In conftest.py (everything stays the same):
@pytest.fixture
def test_api_sqlite_mp(test_sqlite_mp):
    return Platform(_backend=RestTestBackend(test_sqlite_mp.backend))


@pytest.fixture
def test_api_pgsql_mp(test_pgsql_mp):
    return Platform(_backend=RestTestBackend(test_pgsql_mp.backend))

# In another file:
api_platforms = pytest.mark.parametrize(
    "test_mp",
    [
        "test_api_sqlite_mp",
        "test_api_pgsql_mp",
    ],
)

# And finally, for the function:
@api_platforms
def test_index_model(test_mp, request):
    test_mp = request.getfixturevalue(test_mp)
    ...

After uninstalling pytest-lazy-fixture, my tests are running just fine again. Hope this helps 😃

But seriously though, this should be a built-in feature in pytest itself.

There might be one more thing you can do: show the pytest devs in their existing issue to integrate pytest-lazy-fixture in core pytest that you’re interested in that 😃

Yeah, the only way forward is for the author of the new library to look at this project and fill in the missing functionality in theirs.

I still get an error with https://github.com/pytest-dev/pytest/pull/11888:

______________________ ERROR collecting tests/test_prettytable.py _______________________
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pluggy/_hooks.py:501: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pluggy/_manager.py:119: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
../pytest/src/_pytest/python.py:274: in pytest_pycollect_makeitem
    return list(collector._genfunctions(name, obj))
../pytest/src/_pytest/python.py:489: in _genfunctions
    self.ihook.pytest_generate_tests.call_extra(methods, dict(metafunc=metafunc))
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pluggy/_hooks.py:562: in call_extra
    return self._hookexec(self.name, hookimpls, kwargs, firstresult)
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pluggy/_manager.py:119: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pytest_lazyfixture.py:74: in pytest_generate_tests
    normalize_metafunc_calls(metafunc, 'funcargs')
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pytest_lazyfixture.py:81: in normalize_metafunc_calls
    calls = normalize_call(callspec, metafunc, valtype, used_keys)
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pytest_lazyfixture.py:105: in normalize_call
    valtype_keys = set(getattr(callspec, valtype).keys()) - used_keys
E   AttributeError: 'CallSpec2' object has no attribute 'funcargs'

There is no traceback. This was the output I got when trying to run that trivial repro test module with pytest 7:

collected 2 items                                                                                                                                                                                                                                                                                                                         

tests/test_foo.py::test_foo[service1] ERROR                                                                                                                                                                                                                                                                                         [ 50%]
tests/test_foo.py::test_foo[service2] ERROR                                                                                                                                                                                                                                                                                         [100%]

================================================================================================================================================================= ERRORS ==================================================================================================================================================================
__________________________________________________________________________________________________________________________________________________ ERROR at setup of test_foo[service1] ___________________________________________________________________________________________________________________________________________________
The requested fixture has no parameter defined for test:
    tests/test_foo.py::test_foo[service1]

Requested fixture 'fixture1' defined in:
tests/test_foo.py:7

Requested here:
venv38/lib64/python3.8/site-packages/_pytest/fixtures.py:693
__________________________________________________________________________________________________________________________________________________ ERROR at setup of test_foo[service2] ___________________________________________________________________________________________________________________________________________________
The requested fixture has no parameter defined for test:
    tests/test_foo.py::test_foo[service2]

Requested fixture 'fixture1' defined in:
tests/test_foo.py:7

Requested here:
venv38/lib64/python3.8/site-packages/_pytest/fixtures.py:693
============================================================================================================================================================ 2 errors in 0.04s ============================================================================================================================================================

I mainly used this package because it alowed me to use parametrized fixtures in parametrized tests, producing a product of test cases. I have tested @glatterf42 's and @PrieJos 's solution but both produced errors Failed: The requested fixture has no parameter defined for test when I used them with parametrized fixtures. Does anyone have a solution for this?

I’ve already raised an issue about this. I’m sticking with pytest 7.x in affected projects until it’s fixed.

I didn’t look at the code in detail, but if the only problem is the call to getfixtureclosure, pytest-dev/pytest#11888 will fix the problem.

I believe the order of arguments also changed, or am I misreading the 3 different versions in pytest-lazy-fixutre?

I still get an error with pytest-dev/pytest#11888:

And yes, the other fix is that CallSpec2.funcargs was merged into CallSpec2.params? At least, stopping to access funcargs and only accessing params did the trick. (So yes, actually my patch up there is not backwards compatible, right now.)