assert-on-string-literal / W0129#

Message emitted:

Assert statement has a string literal as its first argument. The assert will %s fail.

Description:

Used when an assert statement has a string literal as its first argument, which will cause the assert to always pass.

Correct code:

def test_division():
    a = 9 / 3
    assert a == 3

Problematic code:

def test_division():
    a = 9 / 3
    assert "No ZeroDivisionError were raised"  # [assert-on-string-literal]

Additional details:

Directly asserting a string literal will always pass. The solution is to test something that could fail, or not assert at all.

For unittest assertions there is the similar redundant-unittest-assert / W1503 message.

Related links:

Created by the basic checker.