Skip to content

Python · testing

fixture-returns-bare-tuple

python:fixture-returns-bare-tuple

Fixture returns a bare multi-field tuple — return a NamedTuple so consumers destructure by name.

Code
SARJ044
Default
error
Fix
none
Languages
python

Why

Positional fixture results make call sites opaque and allow reordered fields to bind incorrectly.

Fix

Return a `NamedTuple`, frozen dataclass, or another value whose fields have stable names.

Before / after

Executed by this rule’s unit tests.

Before

Fixture fields are positional

tests/conftest.py · focus
import pytest

@pytest.fixture
def stores():
    return org_store, user_store

After

Fixture fields are named

tests/conftest.py · focus
import pytest

@pytest.fixture
def stores():
    return Stores(org=org_store, user=user_store)

Limits

  • Only pytest and pytest-asyncio fixtures in test paths are analyzed.
  • Factory closures and single-field tuples are allowed.