jeudi 7 décembre 2017

Chaining pytest fixtures

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:

@pytest.fixture(params=make_shapes())
def shape(request):
    return request.param

@pytest.fixture()
def rectangle(shape):
    if request.param['type'] == 'rectangle'
        return request.param
    elif:
        # Skip

def test_all_shapes(shape):
    assert shape_test(shape)

def test_recs(rectangle):
    assert rectangle_test(rectangle)

I've thought about giving make_shape a filter and having both fixtures use that as a params, but this has led to another problem when I want those shapes generated in make_shapes to be based on a fixture themselves.

Thanks.

Aucun commentaire:

Enregistrer un commentaire