Skip to content

Add typing information for parameterized fixtures #8073

Description

@tobiasdiez

What's the problem this feature will solve?

Add typing information for parameterized fixtures to have better support for type checkers.

Describe the solution you'd like

Given a fixture like

@pytest.fixture(params=["--setup-only", "--setup-plan", "--setup-show"])
def mode(request):
    return request.param

what is the type of request? I thought it would be FixtureRequest but this class doesn't have a param object. Thus I suggest to add a generic class ParametrizedFixtureRequest[T] where T is the type of the parameter. Thus in the above example one could annotate request: ParametrizedFixtureRequest[str] and then the type checker would know that request.param is a string.

Alternative Solutions

Additional context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: typingtype-annotation issuetype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions