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".
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.
andassert 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
or expressionsassert 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
or is excludedassert 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.
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.
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:
assert a and b (and longer and chains) that combine independent conditionsassert not (a or b) (De Morgan-equivalent negation of an or expression)Plain assert a or b is not flagged, because splitting it would change the meaning of the test.
def test_user(user):
assert user.is_active and user.is_verified # Noncompliant
def test_user(user):
assert user.is_active
assert user.is_verified
def test_axis_hidden(axis):
assert not (axis.visible or axis.label_visible) # Noncompliant
def test_axis_hidden(axis):
assert not axis.visible
assert not axis.label_visible