What happens when an assert statement in a pytest test is false?
def test_total():
assert calculate_total([10, 20]) == 30Options
- Nothing happens and the test continues to run
- The test fails, and pytest shows the compared values (Correct option)
- Python crashes with a traceback and stops all tests
- The test is skipped and flagged in the report
Answer
The test fails, and pytest shows the values that were compared
Why
assert condition raises an AssertionError when the condition is false. pytest catches it, marks the test as FAILED and shows a detailed message, e.g. assert 25 == 30, so you see what the code actually returned.
If the condition is true, nothing happens and the test passes.
Remember
assert false → test fails with the compared values shown.