[pytest-dev] Help with parametrized fixtures

Nikolaus Rath Nikolaus at rath.org
Wed Nov 26 21:21:04 CET 2014


I have a parametrized fixture foo, and some test cases that use it:

def foo(request):
    # ...
    return foo_f

def test_1(foo):
    # ...

def test_2(foo):
    # ....

Now, I'd like to add an additional test, but running it only makes sense
for some of the fixture parameters. So far I've solved this by providing
the parameter value as a fixture attribute and skipping "unsupported" values:

def foo(request):
    # ...
    foo_f.param = request.param
    return foo_f

def test_3(foo):
    if foo.param not in (1,4,5):
        raise pytest.skip("doesn't make sense")

This works, but I don't like it very much because it means that the test
suite can never be executed without skipping some tests. I'd rather
reserve skipping for cases where the test could in principle be
executed, but for some reason cannot work at the moment (e.g. because
there's no internet, or a required utility is not installed).

Is there a way to solve the above scenario without skipping tests?

Ideally, I'd be able to do something like this:

def test_3(foo):


GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«

More information about the pytest-dev mailing list