Skip to content

Testing (Pytest)

BetterPy's largest feature group — 4 features that supercharge your pytest workflow with fixture management, fixture inspections, parametrize helpers, mocking support, assertions, and test tree navigation.


Fixtures

BetterPy provides first-class, deep integration for pytest fixtures, refactorings, inspections, and documentation directly inside the IDE.

Pytest fixture documentation

Since 2026.05.2 · Maturity Stable · Issues PY-66245

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.


Parametrize

Pytest parametrized case run gutter icon

Since 2026.06.0 · Maturity Incubating · Issues PY-88558, PY-46650

This feature adds run gutter icons for individual pytest.mark.parametrize cases.

How to use it

Put each parametrized case on its own line, then use the gutter run icon beside the case to run only that pytest node.

import pytest

@pytest.mark.parametrize("value", [
    "admin",
    "guest",
])
def test_role(value):
    assert value
test_roles.py::test_role[guest]

Notes

  • The line marker appears only when BetterPy can infer the exact pytest case ID.
  • Explicit ids from ids=[...] and pytest.param(..., id="...") are supported.
  • The feature is gated by the Pytest parametrized case run gutter icon setting under Settings | BetterPy | Testing (Pytest) | Parametrize.

Assertions & Test Editing

Use actual test outcome

Since 2026.06.0 · Maturity Incubating

Replaces assertion expected values with the actual value from the last failed test run.

How to invoke: ⌥⏎ / Alt+Enter on a failed assertion → "BetterPy: Use actual test outcome"

def test_total():
    assert calculate_total([10, 20]) == 25  # Failed: got 30
def test_total():
    assert calculate_total([10, 20]) == 30

Pytest failed line inspection

Since 2026.06.0 · Maturity Incubating · Issues PY-32337, PY-61067

Marks the line where a pytest test failed, providing visual feedback directly in the editor.

def test_total():
    total = calculate_total([10, 20])
    assert total == 25
def test_total():
    total = calculate_total([10, 20])
    assert total == 25  # highlighted when pytest reports this line as failed

Notes

  • The highlight is based on the last pytest failure location remembered by BetterPy.
  • The feature works together with Use actual test outcome when an assertion diff is available.
  • The feature is gated by the Pytest failed line inspection setting under Settings | BetterPy | Testing (Pytest) | Assertions & Test Editing.