This rule raises an issue when a @pytest.fixture yields a value with no teardown code after the yield.
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()
A useless yield suggests teardown that does not exist, which misleads readers about fixture lifecycle and resource ownership.
When a fixture has no teardown, replace yield with return.
import pytest
@pytest.fixture
def useless_yield():
data = load()
yield data # Noncompliant
import pytest
@pytest.fixture
def useless_yield():
return load()