pytest-dev / pytest-dev/pytest
Show return type annotations in `--fixtures` and `--fixtures-per-test`
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?
Knowing the annotated return types of fixtures in --fixtures could help users to understand what a fixture is/does, especially for fixtures that are missing a docstring.
Describe the solution you'd like
Something like
import pytest
@pytest.fixture
def answer() -> int:
"""Answer to the Ultimate Question of Life, the Universe, and Everything."""
return 42
currently displays:
------------------------- fixtures defined from test_x -------------------------
answer -- test_x.py:4
Answer to the Ultimate Question of Life, the Universe, and Everything.
but could display:
------------------------- fixtures defined from test_x -------------------------
answer -> int -- test_x.py:4
Answer to the Ultimate Question of Life, the Universe, and Everything.
or
------------------------- fixtures defined from test_x -------------------------
answer -- test_x.py:4
Answer to the Ultimate Question of Life, the Universe, and Everything.
Return type: int
or any other color of bike shed.
Alternative Solutions
Looking at the source code at the indicated location. Works, but is an extra step.
Additional context
I'm a bit confused between typing.get_type_hints(), inspect.get_annotations() (pre-3.14) and annotationlib (3.14+), and which one would be best to use for this purpose.
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 locating the CLI entry points that implement --fixtures and --fixtures-per-test, then inspect how fixture names, locations, and docstrings are currently rendered. Compare the available Python annotation APIs and existing compatibility constraints, and define one output format with tests covering annotated and unannotated fixtures; done means both options consistently show the chosen return-type information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100