I have a fixture that creates a list of items during tests. I want to have another fixture which is parametrized with values generated by the first one.
Example code
import random
import pytest
@pytest.fixture
def values():
return [random.randint(0, 100) for _ in range(10)]
@pytest.fixture
def value(request):
return request.param
@pytest.mark.parametrize("value", params=values):
def test_function(value):
assert value > 0
The problem with above code is that values
is a function and not a list. I did quite a lot of digging but didnt find any way to unpack fixture to parametrize another with it.
Im aware that i can pass values
fixture and iterate over it in tests, but that not a good solution since i want to see which values cause test to fail.
Im also open to alternative solutions, for example if it is possible to run subtests from started test.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…