pytest-dev / pytest-dev/pytest
type hinting for request.param (such as SubRequest[MyType])
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
I could presumably submit a PR for this if it making SubRequest a Generic is deemed a good approach.
What's the problem this feature will solve?
When type hinting a parameter for a request fixture the request.param attribute is typed as Any and I have to # type: ignore[no-any-return].
Describe the solution you'd like
Long term, a plugin would be nice to automatically relate the .param to it's source in the @pytest.fixture() decoration. Short term, Request could just be a Generic.
This would allow me to use request: _pytest.fixtures.SubRequest[MyType] instead of the type ignore and get any useful hints on the .param attribute inside the fixture as well as return type verification.
Alternative Solutions
I have not tried anything beyond the type ignore.
Additional context
None.
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 tracing _pytest.fixtures.SubRequest and the request.param attribute typing described in the issue. Compare the proposed generic annotation with the existing fixture typing approach. Done means a request annotated as SubRequest[MyType] provides MyType for request.param and supports return-type verification without a type ignore.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100