This rule raises an issue when a pytest fixture uses the deprecated @pytest.yield_fixture decorator.
Before pytest 3.0, fixtures that needed teardown used @pytest.yield_fixture. Since then, @pytest.fixture supports
yield for setup and teardown. pytest.yield_fixture remains only as a deprecated alias:
@pytest.yield_fixture # Deprecated
def resource():
value = acquire()
yield value
release(value)
Replace it with @pytest.fixture; the yield body stays the same.
Deprecated @pytest.yield_fixture triggers deprecation warnings and will break on newer pytest versions. Migrating to
@pytest.fixture keeps fixture code compatible and consistent with current pytest APIs.
Replace @pytest.yield_fixture with @pytest.fixture. Keep the same yield body for setup and teardown.
import pytest
@pytest.yield_fixture # Noncompliant
def old_style():
value = 1
yield value
import pytest
@pytest.fixture
def old_style():
value = 1
yield value