DEV Community

abbazs
abbazs

Posted on • Edited on

1

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.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (1)

Collapse
 
abbazs profile image
abbazs

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

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs