Skip to content
Sarj Code Standards

no-statically-truthy-assertion

An assertion condition is statically truthy, including deferred expressions and test-local scalar setup.

Why

A condition that stays truthy whenever evaluation succeeds cannot reject an incorrect result and often means the intended condition was wrapped in a container, deferred without execution, or placed in the message slot.

Fix

Assert an explicit runtime-derived condition. If the test only requires an operation not to raise, evaluate it directly and retain any meaningful follow-up assertion. Consume generator values or call the lambda when their result is the contract; choose empty-input behavior explicitly.

Examples

Before — flagged The intended condition became an assertion message
tests/test_service.py
def test_service(response):
assert True, response.status_code == 200
After — preferred Assertion checks runtime output
tests/test_service.py
def test_service(response):
assert response.status_code == 200
Before — flagged A generator object does not check the yielded conditions
tests/test_service.py
def test_values(rows):
checks = (row.is_valid for row in rows)
assert checks
After — preferred Consume the conditions when the contract requires every row to be valid
tests/test_service.py
def test_values(rows):
checks = (row.is_valid for row in rows)
assert all(checks)
Before — flagged A test asserts only on its own fixed setup
tests/test_service.py
def test_service():
status = "ok"
assert status == "ok"
After — preferred Assert on a value returned by the application
tests/test_service.py
def test_service():
status = service_status()
assert status == "ok"

Formerly: no-tautological-expect