Skip to main content

SKY-A101 · AI-code defects

Test assertion weakened

Medium

HIGH when the change skips a test or marks it xfail, removes an exception assertion such as pytest.raises, or deletes a negative test (one named for rejecting bad input). LOW for changed or removed snapshot content.

A test is weakened when a change replaces a precise check with a vague one: == 2400 becomes is not None, pytest.raises(ValueError, match=…) disappears, or the test gets skipped. SKY-A101 compares each changed test file with the base version and reports these swaps.

Languages
Python tests (pytest, unittest), JavaScript/TypeScript tests (Jest, Vitest, node:assert), snapshot files
Turned on by
skylos . --ai-defects --diff origin/main (or -a) on a change; also listed as advice by skylos done
Quality gate
counted toward the gate limits (full and diff scans). Counts toward max_ai_defects. skylos done lists it as advice and does not block on it.
Finding type
review
Catalog name
Test assertion weakening
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A coding agent that cannot make a test pass sometimes edits the test instead of the code. The suite stays green while the behaviour it protected is no longer checked, and reviewers rarely spot a one-line change in a test file.

What Skylos flags

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

billing/invoices.py · Python · changed
"""Invoice maths for the checkout service.""" Removed: TAX_RATE = 0.2Added: TAX_RATE = 0.25  def calculate_total(items):    subtotal = sum(item["price"] * item["qty"] for item in items)    return round(subtotal * (1 + TAX_RATE))
tests/test_invoices.py · Python · changed
from billing.invoices import calculate_total  def test_total_includes_tax():    items = [{"price": 1000, "qty": 2}]    total = calculate_total(items) Removed:     assert total == 2400Added:     assert total is not None

What Skylos leaves alone

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

billing/invoices.py · Python · changed
"""Invoice maths for the checkout service.""" Removed: TAX_RATE = 0.2Added: TAX_RATE = 0.25  def calculate_total(items):    subtotal = sum(item["price"] * item["qty"] for item in items)    return round(subtotal * (1 + TAX_RATE))
tests/test_invoices.py · Python · changed
from billing.invoices import calculate_total  def test_total_includes_tax():    items = [{"price": 1000, "qty": 2}]    total = calculate_total(items) Removed:     assert total == 2400Added:     assert total == 2500

Why Skylos leaves it alone

The tax rate changed and the test still checks one exact value, the new one. Changing an expected value is a normal part of changing behaviour; only a swap from a precise check to a vague one is reported.

How Skylos decides

  1. Runs with --ai-defects when there is a change to compare: in a diff scan (--diff or --diff-base), or in a full scan of a Git checkout with uncommitted changes (in CI, the pull request's changes when the base branch is known and fetched). It reads the Git diff of each changed file against the base; untracked files have no diff and are skipped.
  2. Looks only at test files: a tests, test or __tests__ folder anywhere in the file's full path, test_*, *_test.py, test.py and tests.py names, .test. and .spec. files, and snapshot files.
  3. Splits each changed hunk by test, and classes every removed and added line. Strong checks compare a value or an exception: ==, <, in, pytest.raises, assertEqual, toBe, toEqual, toThrow. Weak checks only test that something exists or is truthy: a bare assert x, is not None, assertTrue, assertIsNotNone, toBeDefined, toBeTruthy.
  4. For each test in the hunk, reports the first weakening, in this order: a skip or xfail added; snapshot content changed or removed; an exception check loosened (match= dropped, widened to Exception) or removed; a negative test deleted; a mock check broadened (assert_called_once_with to assert_called); spec= or autospec removed from a mock; an expected value replaced by ANY; == v widened to in (v, …); a value check turned into a length check; a behaviour check replaced by is not None; or a strong check replaced by a weak one with no new strong check in the same hunk.
  5. Reports on the added line in the new file. A hunk that only deletes lines (a removed pytest.raises, a deleted negative test) is reported at its line in the base version, and only by a full scan: a --diff scan drops findings on deleted lines. In skylos done the findings are advice and do not block.

How to fix it

Keep the precise assertion and update the expected value to the new, intended behaviour. If the value really cannot be known any more, say why in the pull request and test a property that still matters, such as the type or a range.

Fix · Python
assert total == 2500

When it can be wrong

  • A deliberate contract change, such as a function that now returns an opaque ID instead of a number, is reported. That is intended: it asks the reviewer to confirm the change.
  • A new test file that arrives already skipped is reported as HIGH once it is staged or committed in the diff. skylos done lists it as advice too: it exempts only lines inside a new test's body, and the skip decorator sits above the def.
  • If the checkout itself sits inside a folder named tests or test, every changed file counts as a test file, because the folder check reads the full path.
  • Because checks are compared within one hunk, a precise assertion moved further down the file can leave the weak one reported.
  • It does not see an assertion deleted outright, == 2400 changed to >= 0, a looser pytest.approx tolerance, or an assertion moved into a helper function. In a --diff scan it also misses deletion-only changes such as a removed pytest.raises block.

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

  • On the added line, with the reason the weaker check is right:

    Python
    assert total is not None  # skylos: ignore[SKY-A101] total now comes from pricing
  • [tool.skylos] ignore = ["SKY-A101"] turns the rule off for the project.

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