pytest-dev / pytest-dev/pytest

Add typing information for parameterized fixtures

Open
#8,073 6 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: typing type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing FixtureRequest type and the parameterized-fixture example in the issue. Determine how a generic request type could expose request.param to Python type checkers, then verify the proposed behavior with that example and a type checker.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.