Skip to content

Pytest fixture documentation

Enhances Quick Documentation and member type inference for pytest fixtures across files.

Quick Documentation on a fixture or fixture parameter shows the resolved fixture type, dataclass/Pydantic/TypedDict fields, attribute docstrings, and literal values returned or yielded by simple fixtures. List, tuple, set, and dict literals are rendered across multiple lines so nested fixture data is easier to scan.

Supported fixture cases:

  • Primitive return types such as str, bool, list, dict, set, int, and float.
  • Generator-style fixtures annotated as Generator[T, ...], Iterator[T], Iterable[T], and their async variants; BetterPy documents and infers the yielded value type T.
  • Dataclasses, Pydantic models, and TypedDicts, including inherited fields, default values, and attribute docstrings.
  • Fixtures defined in conftest.py, including fixtures whose returned class is declared inside the fixture body.
  • The built-in request fixture, which is typed as _pytest.fixtures.SubRequest when available.

Parametrized test arguments are ignored because they shadow fixtures with the same name.

How to invoke: F1 / Ctrl+Q on a fixture parameter.

Example:

import pytest


@pytest.fixture
def api_config() -> dict:
    return {
        "base_url": "https://api.example.test",
        "headers": {"Accept": "application/json"},
        "timeouts": [1, 5, 10],
    }


def test_client(api_config):
    ...

Quick Documentation shows the fixture type and the returned dictionary value as a multiline block, including nested dictionaries and lists.