Skip to content

no-repeated-test-body

Substantial sibling pytest tests repeat the same structural body.

Why

Copy-pasted tests drift independently and obscure the input dimension that changes behavior.

Fix

Parameterize literal-varying copies with descriptive ids when they exercise one contract; correct or remove verbatim copies that never received their intended edit.

Examples

Before — flagged A copied test never received its intended edit
tests/test_jobs.py
def test_starts_job():
job = build_job()
job.run()
assert job.done
def test_stops_job():
job = build_job()
job.run()
assert job.done
After — preferred Sibling tests preserve distinct API contracts
tests/test_api.py
def test_delete_environment():
response = client.delete("/api/environments/3/")
result = response.json()
assert result["ok"]
def test_delete_schedule():
response = client.delete("/api/schedules/3/")
result = response.json()
assert result["ok"]
Before — flagged Consecutive short cases repeat the same call and assertion
tests/test_parser.py
def test_parse_one():
result = parse("a")
assert result == 1
def test_parse_two():
result = parse("b")
assert result == 2
def test_parse_three():
result = parse("c")
assert result == 3
After — preferred One named case table exposes the changing inputs
tests/test_permissions.py
import pytest
@pytest.mark.parametrize("role", ["admin", "editor"], ids=["admin", "editor"])
def test_can_delete(role):
user = make_user(role)
allowed = can_delete(user)
assert allowed

Formerly: duplicate-test-body