Skip to content

Pytest Deprecated yield_fixture

Reports pytest.yield_fixture and offers to replace it with pytest.fixture.

This inspection applies only when the file's interpreter uses pytest 9.2 or later. Older interpreters and unresolved pytest versions do not receive these warnings. The feature can be toggled independently under Settings → BetterPy → Testing / Pytest → Fixture Inspections.

Use @pytest.fixture instead of @pytest.yield_fixture; ordinary fixtures already support yield. The inspection resolves module aliases and directly imported names, leaving unrelated shadowed names alone. The quick-fix preserves module aliases and the visible direct-import name (from pytest import fixture as yield_fixture), avoiding collisions with existing fixture bindings without changing fixture arguments or the generator body.