Skip to content
Sarj Code Standards

production-derived-test-cases

Warn when pytest membership-contract cases are derived only from the first-party production collection.

Why

When exact eligibility or support membership is contractual, deriving cases from production lets a member change without an independent test oracle failing.

Fix

For contractual membership, define a literal expected table, assert the production collection equals it, and drive behavior from the expected table. Suppress the warning with rationale for an intentional dynamic sweep.

Examples

Before — flagged Do not derive cases from production eligibility
app/tests/test_models.py
import pytest
from app.models import ELIGIBLE_MODELS
@pytest.mark.parametrize("model", ELIGIBLE_MODELS)
def test_model(model):
assert build(model).tier == "priority"
After — preferred Drive behavior from an independent expected table
app/tests/test_models.py
import pytest
from app.models import ELIGIBLE_MODELS
EXPECTED_MODELS = ("a", "b")
def test_model_membership():
assert ELIGIBLE_MODELS == EXPECTED_MODELS
@pytest.mark.parametrize("model", EXPECTED_MODELS)
def test_model(model):
assert build(model).tier == "priority"
Before — flagged A fixture equality does not observe the imported production collection
app/tests/test_models.py
import pytest
from app.models import ELIGIBLE_MODELS
def test_membership(ELIGIBLE_MODELS):
assert ELIGIBLE_MODELS == ("a", "b")
@pytest.mark.parametrize("model", ELIGIBLE_MODELS)
def test_model(model):
assert build(model)
After — preferred A fresh local expected table observes the actual production collection
app/tests/test_models.py
import pytest
from app.models import ELIGIBLE_MODELS
def test_membership():
expected = ["a", "b"]
assert ELIGIBLE_MODELS == expected
@pytest.mark.parametrize("model", ELIGIBLE_MODELS)
def test_model(model):
assert build(model)