pytest-dev / pytest-dev/pytest
Add typing information for parameterized fixtures
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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