This rule raises an issue when a @pytest.fixture yields a value with no teardown code after the yield.

Why is this an issue?

A fixture should use yield only when there is teardown after the test. Yielding with nothing afterward is equivalent to return, but reads as if cleanup were intended:

@pytest.fixture
def useless_yield():
    data = load()
    yield data

Use return when no teardown is needed:

@pytest.fixture
def useless_yield():
    return load()

What is the potential impact?

A useless yield suggests teardown that does not exist, which misleads readers about fixture lifecycle and resource ownership.

How to fix it

When a fixture has no teardown, replace yield with return.

Code examples

Noncompliant code example

import pytest

@pytest.fixture
def useless_yield():
    data = load()
    yield data  # Noncompliant

Compliant solution

import pytest

@pytest.fixture
def useless_yield():
    return load()

Resources

Documentation

Related rules