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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

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

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay