问题
I've been unable to find the magic keywords to google this problem or find it in the pytest
documentation.
I'm looking to be able to setup my tests to combine multiple fixtures into a single fixture - or inversely filter fixtures from another fixture. An example will explain it much better:
import pytest
@pytest.fixture(params=[0,1,2,3,4,5,6])
def number(request):
return request.param
@pytest.fixture()
def odd_number(number):
if number % 2 == 1:
return number
else:
return None # Skip (or some kid of filter)
def test_all_positive(number): # want to be called with 0, 1, 2, 3, 4, 5, and 6
assert number >= 0
def test_all_odds_positive(odd_number): # want to be called with 1, 3, and 5
assert odd_number >= 0
This is clearly not the the way pytest
expects me to get the effect I want the odd_number
fixture being passed into test_all_odds_positive
to not include None
s.
来源:https://stackoverflow.com/questions/47696002/chaining-pytest-fixtures