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) == 5Related terms
- pytest — A popular Python testing framework that finds test functions automatically and reports failures with detailed comparisons.
- unit test — An automated check of one small piece of code, such as a single function, that runs quickly and on its own.
Taught in
- Variables And Assignment — Hands-on Python: Complete Video Course & Book
- Literals, Identifiers And Keywords — Hands-on Python: Complete Video Course & Book
- Testing With pytest — Hands-on Python: Complete Video Course & Book
- Handlers, args, raise And assert — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exceptions Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep