Skip to main content

SKY-L040 · Logic and resilience

Constant assertion in test

Low

An assert in a test whose condition is made only of literals and is always true, such as assert True or assert 1 == 1. It can never fail, so it checks nothing.

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 test passes whatever the code under test does. Coding agents write such asserts to make a test go green; the suite then reports coverage of behaviour that is not checked at all.

What Skylos flags

tests/test_pricing.py · PythonReported on line 6
from shop.pricing import cart_total  def test_cart_total_applies_discount():    total = cart_total([{"price": 100, "qty": 2}], discount=0.1)    assert True

What Skylos leaves alone

tests/test_pricing.py · Python
from shop.pricing import cart_total  def test_cart_total_applies_discount():    total = cart_total([{"price": 100, "qty": 2}], discount=0.1)    assert total is not None

Why Skylos leaves it alone

This check is weak, but it is not constant: it reads total, a value the code under test produced, and fails if cart_total returns None. Skylos only reports conditions it can prove true from literals alone.

How Skylos decides

  1. Runs with --quality on Python test files that pytest would collect under the project's settings (python_files, testpaths, norecursedirs; test_*.py and *_test.py by default) and on unittest.TestCase classes whose base is proven by the imports.
  2. Looks only at directly declared test functions and methods. Skipped or xfail tests, conftest.py, fixture and snapshot folders, and nested functions are left out.
  3. Reports an assert whose condition contains only literals, tuples, lists, not, and/or, +/- and comparisons, and evaluates to true. Any name, call or attribute stops the check. Asserts Skylos knows can never run are skipped.
  4. Reports LOW on the line of the assert.

How to fix it

Assert the result the test is named after.

tests/test_pricing.py · Python · the fix, against the flagged file
from shop.pricing import cart_total  def test_cart_total_applies_discount():    total = cart_total([{"price": 100, "qty": 2}], discount=0.1)Removed:     assert TrueAdded:     assert total == 180

When it can be wrong

  • A smoke test that only checks that an import or a call does not raise, and ends with assert True to say so, is reported. Removing the assert keeps the same meaning.

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 line of the assert.

    Python
    assert True  # skylos: ignore[SKY-L040] import smoke test
  • [tool.skylos] ignore = ["SKY-L040"] turns the rule off for the project.

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