Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the request argument coming from in pytest fixtures?

Tags:

python

pytest

I have a question with the request argument in the following code:

@pytest.fixture(scope="module")
def run_id(request):
    return request.config.getoption("--run-id")

In that line of code, where are we getting the request argument from? I searched the repo and request isn't defined as a fixture.

like image 216
tjt Avatar asked Sep 12 '25 03:09

tjt


1 Answers

The request fixture gets you access to a FixtureRequest instance. It is made available and injected manually by pytest for every test. It is used for accessing some pytest internals, in cases where you want to do something dynamic with pytest.

Its only mainstream use case (IMO) is being used in a fixture to provide access to the request.param attribute (for parametrized fixtures). In addition to it being a critical part of a lot of advanced / unusual pytest use cases.

like image 102
Bill Huneke Avatar answered Sep 14 '25 18:09

Bill Huneke