Lazy fixtures not working at all
See original GitHub issueI had a few lazy fixtures loaded in some of my tests like this:
@pytest.mark.parametrize('user_group', [
pytest.lazy_fixture('user_group_national_manager'),
pytest.lazy_fixture('user_group_regional_manager'),
pytest.lazy_fixture('user_group_lwi_staff')
])
Now, when the tests are being loaded it fails collecting them with:
/usr/local/lib/python3.6/dist-packages/pluggy/hooks.py:258: in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:67: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:61: in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
/usr/local/lib/python3.6/dist-packages/_pytest/python.py:242: in pytest_pycollect_makeitem
res = list(collector._genfunctions(name, obj))
/usr/local/lib/python3.6/dist-packages/_pytest/python.py:432: in _genfunctions
self.ihook.pytest_generate_tests(metafunc=metafunc)
/usr/local/lib/python3.6/dist-packages/pluggy/hooks.py:258: in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:67: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:61: in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
/usr/local/lib/python3.6/dist-packages/pytest_lazyfixture.py:70: in pytest_generate_tests
normalize_metafunc_calls(metafunc, 'funcargs')
/usr/local/lib/python3.6/dist-packages/pytest_lazyfixture.py:77: in normalize_metafunc_calls
calls = normalize_call(callspec, metafunc, valtype, used_keys)
/usr/local/lib/python3.6/dist-packages/pytest_lazyfixture.py:101: in normalize_call
_, fixturenames_closure, arg2fixturedefs = fm.getfixtureclosure([val.name], metafunc.definition.parent)
E ValueError: not enough values to unpack (expected 3, got 2)
If I changed the code to use tuples or arrays, the tests run but the lazy fixture is not loaded making the tests fail:
@pytest.mark.parametrize('user_group', [
(pytest.lazy_fixture('user_group_national_manager'),),
(pytest.lazy_fixture('user_group_regional_manager'),),
(pytest.lazy_fixture('user_group_lwi_staff'),)
])
assert response.status_code == 200
E assert 403 == 200
E + where 403 = <HttpResponseForbidden status_code=403, "text/html">.status_code
This was working properly before the upgrade to 0.5.0
I tried to use the format specified in the README with no luck. I had to remove the lazy fixture and use a different approach in the meantime.
Any idea of what’s broken?
FYI, each fixture just creates a Group and adds the user to the created group. I assert the groups the user belongs to and it belongs to none so the fixture is not loaded when the test runs.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Pytest parametrized fixture with pytest-lazy-fixture fails if ...
Clearly debugging the plugin manager of pytest is unfeasible but I noticed the pytest_configure function inside pytest-lazy-fixture never gets ...
Read more >pytest-lazy-fixture - PyPI
It helps to use fixtures in pytest.mark.parametrize. ... Issues. If you encounter any problems, please file an issue along with a detailed description....
Read more >PROPOSAL: Parametrize with fixtures — pytest documentation
This document outlines a proposal around using fixtures as input of parametrized tests or fixtures. Problem¶. As a user I have functional tests...
Read more >Welcome to pytest-factoryboy's documentation! — pytest ...
Fixtures are contributed to the same module where register function is called. ... import pytest from pytest_factoryboy import register, LazyFixture ...
Read more >Lazy Setup at XUnitPatterns.com
We can avoid this problem by having each test use Lazy Setup to set up the fixture if it is not already set...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Published new version
0.5.1
with fix from @YannickJadoul.Thanks @brian-barba-hernandez for opening the issue!
@TvoroG You’re welcome, thanks for the fix!