Skip to main content

SKY-A120 · AI-code defects

Changed line not checked by tests

Medium

A changed line in non-test Python code that no test runs, or that tests run without noticing when it is wrong. Skylos traces the test run to see which tests execute each changed line, then changes the line on purpose (a mutation, such as >= to >) and reruns those tests: if they all still pass, no test checks that line.

Languages
Python (pytest)
Turned on by
skylos done (compares uncommitted changes with HEAD) or skylos done --base origin/main for a pull request; it needs the test run, so not with --no-tests
Quality gate
not checked (full and diff scans). Only skylos done reports it, in its changed_lines_checked check, which advises by default: the finding is shown but does not fail the verdict. With changed_lines_checked = "block" in [tool.skylos.done.checks] it blocks. The check runs only after the blocking checks pass and the tests pass.
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

Coverage alone says a line ran, not that a test would catch a mistake in it. A coding agent can change a boundary or a condition, see the suite pass, and ship a change no test actually pins down.

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).

shop/pricing.py · Python · changed
"""Volume discounts for wholesale orders."""  def bulk_discount(quantity):Removed:     if quantity >= 10:Added:     if quantity >= 12:        return 0.1    return 0.0
2 committed files the change leaves alone
pyproject.toml · TOML
[project]name = "shop"version = "0.3.0" [tool.pytest.ini_options]testpaths = ["tests"]
tests/test_pricing.py · Python
from shop.pricing import bulk_discount  def test_large_order_gets_discount():    assert bulk_discount(50) == 0.1  def test_single_item_pays_full_price():    assert bulk_discount(1) == 0.0

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).

shop/pricing.py · Python · changed
"""Volume discounts for wholesale orders."""  def bulk_discount(quantity):Removed:     if quantity >= 10:Added:     if quantity >= 12:        return 0.1    return 0.0
tests/test_pricing.py · Python · changed
from shop.pricing import bulk_discount  def test_large_order_gets_discount():    assert bulk_discount(50) == 0.1  def test_single_item_pays_full_price():    assert bulk_discount(1) == 0.0Added:  Added:  Added: def test_discount_starts_at_twelve():Added:     assert bulk_discount(12) == 0.1Added:     assert bulk_discount(11) == 0.0
1 committed file the change leaves alone

pyproject.toml: same as in the flagged example.

Why Skylos leaves it alone

The same threshold change, but a new test checks both sides of it. When Skylos turns >= into >, bulk_discount(12) returns 0.0 and the test fails, so the line is checked.

How Skylos decides

  1. Runs in skylos done, after the blocking checks and the tests_pass check. It needs pytest, and every test must have run and passed; with --no-tests, another test command or failing tests the check is skipped.
  2. Picks the changed lines in non-test Python files (not test_*.py, *_test.py, conftest.py or files under test, tests or testing folders, and not migrations), anchored to their statement or condition. Logging calls, imports, docstrings, type hints and module-level code are skipped.
  3. Uses the trace of the test run to find which tests execute each line. A line no test runs is reported once per function ("No test runs ...").
  4. For a line that tests run, makes one mutation chosen by what the line does (flip a comparison, negate a condition, change a return value, a number, an operator or an argument, or drop a call), loads it in memory inside the test process and reruns only the tests that run the line. If all of them still pass, it reports "No test fails if ...". The working tree is never modified.
  5. At most 20 mutants run, within changed_lines_budget_seconds (120 by default). Lines past either limit are counted as not checked, never as passing.

How to fix it

Add a test that would fail if the changed line were wrong. For a threshold, check the values just on each side of it.

Fix · Python
def test_discount_starts_at_twelve():    assert bulk_discount(12) == 0.1    assert bulk_discount(11) == 0.0

When it can be wrong

  • Some lines are not worth a test, such as a changed default log level or a message string; the finding is advice for that reason.
  • A mutation that does not change behaviour (an equivalent mutant) is reported even though no test could catch it.
  • Only Python run under pytest is checked. Changed lines in other languages, or in projects whose test_command is not pytest, are not checked.

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

  • skylos done findings ignore # skylos: ignore[...] comments and the [tool.skylos] ignore list. The check only advises by default; to turn it off, commit the mode to the base branch first (the change under review cannot change its own check):

    TOML
    [tool.skylos.done.checks]changed_lines_checked = "off"

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