🧪Assertion
Also known as Assert, expect
A line in a test that says what must be true, or the test fails.
Think of it like
Think of it like a scale. You say the box weighs 5 kilos, then you weigh it.
Example
Emma's test asserts that the total is 6. It is really 5, so pytest prints assert 5 == 6 and marks the test failed.
Why it matters
Assertions are what make a test a test. They turn running code into checking code.
Definition
Example code
console
$ pytest -q test_fail.py
E assert 5 == 6
FAILED test_fail.py::test_total - assert 5 == 6
1 failed in 0.03sCommon mistake
Key takeaways
- 1States what must be true. The expected result.
- 2False means fail. And it shows what it got.
- 3No assertion, no test. It checks nothing.