SKY-L042 · Logic and resilience
Repeated test assertion
Two identical assert statements next to each other in a test, checking a plain local value that cannot have changed in between. The second one can only pass if the first did, so it adds nothing.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
Why it matters
The copy usually replaced a check that was meant to be different, such as the cart total after the count. The test looks thorough while one of its intended checks is missing.
What Skylos flags
from shop.cart import Cart def test_cart_holds_added_items(): cart = Cart() cart.add("apple") cart.add("pear") count = len(cart.items) assert count == 2 assert count == 2What Skylos leaves alone
from shop.cart import Cart def test_cart_total_is_stable(): cart = Cart() cart.add("apple") cart.add("pear") assert cart.total() == 5 assert cart.total() == 5Why Skylos leaves it alone
The repeated line calls cart.total() again, and the second call can return something else if the first one changed the cart. Checking that it does not is a real test. Skylos only reports repeats of plain local values it can prove unchanged.
How Skylos decides
- Runs with
--qualityon Python test files that pytest would collect (test_*.pyand*_test.pyby default) and on provenunittest.TestCaseclasses. Skipped andxfailtests are left out, and so are tests that useglobalornonlocal. - Reports an
assertthat is identical to the statement right before it, when its condition uses at least one name and only compares values with==,!=,is,<and similar, or combines such comparisons. - Every name must be a local known to hold a plain value: a string, number, bool,
Noneor tuple literal, or the result of the builtinlen(). Calls, attributes and subscripts are not proven. - Any statement between the two asserts, or a call in an assignment, resets what is known. Reports LOW on the second
assert.
How to fix it
Replace the copy with the check you meant, here the cart total.
from shop.cart import Cart def test_cart_holds_added_items(): cart = Cart() cart.add("apple") cart.add("pear") count = len(cart.items) assert count == 2Removed: assert count == 2Added: assert cart.total() == 5When it can be wrong
- It misses the same copy-paste on an attribute or call, such as two
assert cart.count == 2lines, because Skylos cannot prove the value did not change.
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 second
assert.Python assert count == 2 # skylos: ignore[SKY-L042] kept for the bisect script[tool.skylos] ignore = ["SKY-L042"]turns the rule off for the project.