This rule raises an issue when a pytest fixture uses the deprecated @pytest.yield_fixture decorator.

Why is this an issue?

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.

What is the potential impact?

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.

How to fix it

Replace @pytest.yield_fixture with @pytest.fixture. Keep the same yield body for setup and teardown.

Code examples

Noncompliant code example

import pytest

@pytest.yield_fixture  # Noncompliant
def old_style():
    value = 1
    yield value

Compliant solution

import pytest

@pytest.fixture
def old_style():
    value = 1
    yield value

Resources

Documentation

Related rules