Im trying to use list of one fixture values as parameters into another. Here is my setup:
import pytest
d = {
"first": [1, 2, 3],
"second": [4, 5, 6]
}
@pytest.fixture(params=['first', 'second'])
def foo(request):
return d.get(request.param)
@pytest.fixture(params=[pytest.lazy_fixture('foo')])
def bar(request):
return request.param
def test_1(bar):
pass
The problem is bar()
always get full list as request.param
([1, 2, 3] not values of the list. If in params
of bar()
fixture send data directly, e.g:
@pytest.fixture(params=[1, 2, 3])
def bar(request):
return request.param
def test_1(bar):
pass
Then argument request will work properly (test starts three times). The same situation, if I pass arguments to params
not directly, but from any method without fixture decorator, i.e:
def some():
return [1, 2, 3]
@pytest.fixture(params=some())
def more(request):
return request.param
def test_2(more):
logging.error(more)
pass
So, my question is it possible to obtain data from list one by one and then use it in my test? I've try to 'unparse' list:
@pytest.fixture(params=[i for i in i pytest.lazy_fixture('foo')])
def bar(request):
return request.param
But in this case I get TypeError: 'LazyFixture' object is not iterable