Skip to content

Show return type annotations in --fixtures and --fixtures-per-test #13676

@The-Compiler

Description

@The-Compiler

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytopic: reportingrelated to terminal output and user-facing messages and errors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions