DEV Community

abbazs
abbazs

Posted on • Edited on

How to pass an argument to a pytest fixture?

Update: It is not possible.

I know this question has been asked several times. Yet here I'm seeking help because the existing answers are not addressing this specific question:

Here is what is working:
I've a fixture called indexer (example use case), it simply returns an number starting from 0 to 9

import pytest

# Parametrized fixture
@pytest.fixture(params=range(10))
def indexer(request):
    return request.param

@pytest.mark.parametrize("a", [pytest.lazy_fixture("indexer")])
def test_indexer(a):
    assert isinstance(a, int)
Enter fullscreen mode Exit fullscreen mode

I want to pass an argument for the range function in the fixture like: @pytest.fixture(params=range(max_range)). How can I do it?

I also know that there is a plugin called pytest-repeat. But that is not what I'm looking for.

Top comments (1)

Collapse
 
abbazs profile image
abbazs

It is not possible to do what I'm trying to do.