Skip to main content

SKY-L045 · Logic and resilience

Test assertion always true

Low

An assertion in a test whose condition is true for every value of the names in it: len(x) >= 0, x or True, isinstance(x, object), x is x, or a non-empty tuple, list, set or dict such as assert (x == 1, "message"). SKY-L040 reports conditions made only of literals, like assert True; this rule covers the ones that mention a variable and still cannot fail.

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 assertion looks like a check but passes whatever the code returns. The parenthesised form is a real bug: assert (x == 1, "message") asserts a two-item tuple, which is always true, instead of x == 1 with a message.

What Skylos flags

test_runs.py · PythonReported on line 6
from agents.run_state import deserialize_items  def test_deserialize_items_keeps_string_agents():    result = deserialize_items([{"source_agent": "triage"}])    assert len(result) >= 0

What Skylos leaves alone

test_runs.py · Python
from agents.run_state import deserialize_items  def test_deserialize_items_keeps_string_agents():    result = deserialize_items([{"source_agent": "triage"}])    assert len(result) >= 1    assert result == result

Why Skylos leaves it alone

len(result) >= 1 fails on an empty list. result == result can be false (a NaN, or a class whose __eq__ says so), so Skylos does not call it always true. Neither line is reported.

How Skylos decides

  1. Runs with --quality on the same collected tests as SKY-L044, and only on assertions that run: lines after a return or a proven jump are skipped.
  2. Reports assert with a non-empty tuple, list, set or dict display (no * unpacking), an or chain with an always-true part, len(x) >= 0 or 0 <= len(x) where len is the builtin, isinstance(x, object) where both names are the builtins, and x is x.
  3. In unittest tests it also reports self.assertTrue(True), self.assertFalse(False) and self.assertEqual on two equal literals.
  4. Leaves literal-only conditions to SKY-L040, and does not report x == x, a comparison of two displays such as [a] == [b], or len and isinstance when the file rebinds those names.

How to fix it

Assert on the value the code should produce. For the tuple mistake, drop the parentheses: assert x == 1, "message".

test_runs.py · Python · the fix, against the flagged file
from agents.run_state import deserialize_items  def test_deserialize_items_keeps_string_agents():    result = deserialize_items([{"source_agent": "triage"}])Removed:     assert len(result) >= 0Added:     assert [item.agent_name for item in result] == ["triage"]

When it can be wrong

  • assert len(events) >= 0 # timing dependent is reported even when the author meant "this must not raise". The assertion still checks nothing; remove it, or assert something the timing cannot 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 assertion line.

    Python
    assert len(events) >= 0  # skylos: ignore[SKY-L045] streaming must not raise
  • [tool.skylos] ignore = ["SKY-L045"] turns the rule off for the project.

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