Skip to content

Boolean

assert_that returns a BooleanAssert for True and False. It adds two checks that read better than comparing with is_equal_to(True):

assert_that(user.is_active, description="active flag").is_true()
assert_that(order.is_canceled).is_false()

There are no negations: is_not_true() would mean the same as is_false().

Only real booleans

Values that are only truthy or falsy, such as 1, 0 or "", are not booleans and get the assertion class of their own type. assert_that(1) returns a NumberAssert, which has no is_true(). To check a truthy value, convert it first: assert_that(bool(value)).is_true().

Bases: ObjectAssert[bool]

Assertions for bool values.

assert_that returns this class only for real booleans. Values that are merely truthy or falsy, such as 1, 0 or "", get the assertion class of their own type.

The boolean checks:

  • is_true, is_false

There are no negations: is_not_true would mean the same as is_false. All generic checks of ObjectAssert, such as is_equal_to or is_instance_of, are available as well.

Every check returns the assertion itself, so checks can be chained. A failed check raises AssertionFailedError.

Examples:

assert_that(user.is_active, description="active flag").is_true()
assert_that(response.ok).is_true()
assert_that(order.is_canceled).is_false()

is_false()

Check that the value is False.

Examples:

assert_that(order.is_canceled).is_false()

Returns:

Type Description
Self

This assertion, so that further checks can be chained.

Raises:

Type Description
AssertionFailedError

If the value is not False.

is_true()

Check that the value is True.

Examples:

assert_that(user.is_approved).is_true()

Returns:

Type Description
Self

This assertion, so that further checks can be chained.

Raises:

Type Description
AssertionFailedError

If the value is not True.