This rule raises an issue when a test assertion combines multiple independent conditions with and, or when it asserts the negation of an or expression (assert not (a or b)).

It does not raise an issue on plain assert a or b, because splitting that form would change the meaning from "at least one condition holds" to "all conditions hold".

Why is this an issue?

Composite assertions hide which condition failed. When several checks are joined in a single assert, a failure reports the whole expression as false instead of pointing at the specific condition that broke.

Assertions joined with and

assert a and b verifies two independent facts in one statement. If the assertion fails, the message does not clearly identify whether a, b, or both were false:

def test_user(user):
    assert user.is_active and user.is_verified  # Which condition failed?

Splitting into separate asserts makes each failure actionable:

def test_user(user):
    assert user.is_active
    assert user.is_verified

Negated or expressions

assert not (a or b) is equivalent to asserting that both a and b are false (De Morgan’s law). It has the same opacity problem as an and chain:

def test_axis_hidden(axis):
    assert not (axis.visible or axis.label_visible)  # Which flag is still true?

Split it into independent negated asserts:

def test_axis_hidden(axis):
    assert not axis.visible
    assert not axis.label_visible

Why plain or is excluded

assert a or b means at least one condition must hold. Replacing it with two separate asserts would require both to hold and would change the test’s intent. This rule therefore does not flag that form.

What is the potential impact?

When a composite assertion fails, developers spend extra time deciphering which condition broke. Opaque failure messages slow down debugging and make flaky or partial regressions harder to diagnose. Splitting assertions keeps each check independent and produces clearer failure reports.

How to fix it

Split composite assertions into separate assert statements, one per independent condition. For assert not (a or b), use De Morgan’s law and write assert not a and assert not b.

This applies to:

Plain assert a or b is not flagged, because splitting it would change the meaning of the test.

Code examples

Noncompliant code example

def test_user(user):
    assert user.is_active and user.is_verified  # Noncompliant

Compliant solution

def test_user(user):
    assert user.is_active
    assert user.is_verified

Noncompliant code example

def test_axis_hidden(axis):
    assert not (axis.visible or axis.label_visible)  # Noncompliant

Compliant solution

def test_axis_hidden(axis):
    assert not axis.visible
    assert not axis.label_visible

Resources

Documentation