Skip to main content

SKY-L047 · Logic and resilience

Duplicate test

Low

A test with the same decorators, parameters and body as an earlier test in the same module or class, under a different name. Docstrings and layout are ignored; one changed literal makes it a different test.

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The copy adds run time and checks nothing new. Its name usually promises a different case, such as ..._when_meaningful_test_file_changed next to ..._when_any_test_file_changed, and that case stays untested.

What Skylos flags

test_impact.py · PythonReported on line 10
from review.impact import detect_gaps  def test_allows_change_when_any_test_file_changed():    changed = ["src/billing/tax.py", "tests/test_tax.py"]    findings = detect_gaps(changed)    assert findings == []  def test_allows_change_when_meaningful_test_file_changed():    changed = ["src/billing/tax.py", "tests/test_tax.py"]    findings = detect_gaps(changed)    assert findings == []

What Skylos leaves alone

test_impact.py · Python
import pytest from review.impact import detect_gaps  def test_allows_change_when_any_test_file_changed():    findings = detect_gaps(["src/billing/tax.py", "tests/test_tax.py"])    assert findings == []  def test_reports_change_without_tests():    findings = detect_gaps(["src/billing/tax.py"])    assert findings != []  @pytest.mark.vcr()def test_first_recorded_run():    assert detect_gaps(["src/billing/tax.py"]) != []  @pytest.mark.vcr()def test_second_recorded_run():    assert detect_gaps(["src/billing/tax.py"]) != []

Why Skylos leaves it alone

The first two tests pass different inputs. The last two have the same body, but vcr replays a recording chosen by the test's name, so they can run against different data.

How Skylos decides

  1. Runs with --quality on the same collected tests as SKY-L044, comparing tests of the same module, or of the same class, never across classes.
  2. Two tests match when their parameters, decorators and statements are identical as syntax trees, apart from a leading docstring. The later one is reported and names the first.
  3. Skips bodies that call nothing, a second definition under the same name (Python keeps only the last), and tests whose name selects recorded data: a vcr, cassette, betamax or recording marker, or a snapshot, vcr_cassette, request or regression fixture.

How to fix it

Remove the copy, or change it to cover the case its name describes.

test_impact.py · Python · the fix, against the flagged file
from review.impact import detect_gaps  def test_allows_change_when_any_test_file_changed():    changed = ["src/billing/tax.py", "tests/test_tax.py"]    findings = detect_gaps(changed)    assert findings == []  Removed: def test_allows_change_when_meaningful_test_file_changed():Removed:     changed = ["src/billing/tax.py", "tests/test_tax.py"]Added: def test_reports_change_when_test_file_only_adds_comments():Added:     changed = ["src/billing/tax.py", "tests/test_tax_comments.py"]    findings = detect_gaps(changed)Removed:     assert findings == []Added:     assert findings != []

When it can be wrong

  • Two tests that read different data through a fixture or plugin keyed on the test name Skylos does not know are reported as copies.
  • It misses copies that differ only in a variable name or a comment-only line move, and copies in different classes or files.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Put the marker on the def line of the later test.

    Python
    def test_meaningful_change():  # skylos: ignore[SKY-L047] other cassette
  • [tool.skylos] ignore = ["SKY-L047"] turns the rule off for the project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.