LazyFixture only resolved when used directly, but not in lists etc.
See original GitHub issueMy use case requires preparing lists of things instead of just single things one by one, please see your example adapted accordingly below.
import pytest
@pytest.fixture(params=[
[pytest.lazy_fixture('one')],
[pytest.lazy_fixture('one'), pytest.lazy_fixture('two')],
])
def some_list(request):
return request.param
@pytest.fixture
def one():
return 1
@pytest.fixture
def two():
return 2
def test_func(some_list):
from pprint import pprint
pprint(some_list)
assert 1 in some_list
Inside test_func()
the some_list
will be something like [<LazyFixture "one">, <LazyFixture "two">]
where I would have expected that this had been expanded/resolved to [1, 2]
.
Is there a way to always expand /resolve in a test context no matter how wrapped or nested the LazyFixture
is?
Cheers
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Use pytest.lazy_fixture list values as parameters in another ...
See this answer to a very similar question: by design, fixture values can not be used as lists of parameters to parametrize tests....
Read more >Welcome to pytest-factoryboy's documentation! — pytest ...
Library exports a function to register factories as fixtures. Fixtures are contributed to the same module where register function is called. Factory Fixture¶....
Read more >pytest Documentation
2.3.14 Use fixtures in classes and modules with usefixtures. Sometimes test functions do not directly need access to a fixture object.
Read more >pytest-lazy-fixture
Project description. Use your fixtures in @pytest.mark.parametrize. Installation. pip install pytest-lazy-fixture ...
Read more >Deep dive into Pytest parametrization | by George Shuklin
If a few fixtures are used in one test function, pytest generates a Cartesian product of ... This function is not a fixture,...
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
I’d love to see this supported as well. We have a case where we want to add some metadata about existing fixtures when they are used as part of a different fixture. The metadata doesn’t make sense to include in the original fixtures because it is only relevant in the new context. The natural way to tie the original fixtures and related metadata together would be in the params of the new fixture.
Another place where this shows up is parametrized tests which operate over arbitrary numbers of arguments, which is something I often use.
Toy example:
Here on the third run of the test,
args[0]
will be<LazyFixture "some_fixture">
rather than the result of that fixture; to get the actual result I am forced to use a fixed number of explicitly-named arguments, it seems.