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¶
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, andfloat. - Generator-style fixtures annotated as
Generator[T, ...],Iterator[T],Iterable[T], and their async variants; BetterPy documents and infers the yielded value typeT. - 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
requestfixture, which is typed as_pytest.fixtures.SubRequestwhen 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¶
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.
Notes¶
- The line marker appears only when BetterPy can infer the exact pytest case ID.
- Explicit ids from
ids=[...]andpytest.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¶
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"
Pytest failed line inspection¶
Marks the line where a pytest test failed, providing visual feedback directly in the editor.
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.