assert statement

A statement, assert condition, that does nothing if the condition is true and raises AssertionError if it is false.

In more detail

In pytest, assert is how a test states what should be true, and pytest shows both sides of a failed comparison. Do not use assert to check user input in normal programs, because Python can be run with assertions switched off.

Example

assert add(2, 3) == 5

Related terms

Taught in

References

Certification courses