Skip to content

Python · testing

no-tautological-expect

python:no-tautological-expect

Assertion outcome is fixed entirely by literal values.

Code
SARJ057
Default
error
Fix
none
Languages
python

Why

An always-passing assertion cannot verify runtime behavior and can hide a missing comparison.

Fix

Assert against a value produced by the code under test.

Before / after

Executed by this rule’s unit tests.

Before

Assertion always passes

tests/test_service.py · focus
def test_service():
    assert True

After

Assertion checks runtime output

tests/test_service.py · focus
def test_service(result):
    assert result == 1

Limits

  • Detection covers truthy literal asserts and supported unittest methods with literal-only operands.
  • Always-failing markers, benchmark tests, deliberate match-arm markers, and runtime-value comparisons are excluded.