Skip to content

pytest-fixture-returns-bare-tuple

Pytest fixture exposes a fixed positional record as an unnamed tuple.

Why

Tuple-shaped fixture APIs encode each value's role in its position, so call sites are opaque and a reordered result can silently bind the wrong test dependency.

Fix

Return a NamedTuple, frozen dataclass, or another result object and access its named fields; split independent values into separate fixtures when they do not form one record. Keep the tuple and use an exact SARJ044 suppression when tuple identity or ordering is itself the tested domain contract.

Examples

Before — flagged Fixture consumers must remember field positions
tests/conftest.py
import pytest
@pytest.fixture
def stores():
return org_store, user_store
tests/test_users.py
def test_user_lookup(stores):
org_store, user_store = stores
assert user_store.get("u1")
After — preferred Fixture consumers use named fields
tests/conftest.py
import pytest
from tests.support.stores import Stores
@pytest.fixture
def stores() -> Stores:
return Stores(org=org_store, user=user_store)
tests/support/stores.py
from dataclasses import dataclass
@dataclass(frozen=True)
class Stores:
org: object
user: object
tests/test_users.py
from tests.support.stores import Stores
def test_user_lookup(stores: Stores):
assert stores.user.get("u1")

Formerly: fixture-returns-bare-tuple