Test Overview
This test checks that a function raises a ValueError with the correct message when given invalid input.
This test checks that a function raises a ValueError with the correct message when given invalid input.
import pytest def divide(a, b): if b == 0: raise ValueError("Cannot divide by zero") return a / b def test_divide_by_zero(): with pytest.raises(ValueError) as exc_info: divide(10, 0) assert exc_info.value.args[0] == "Cannot divide by zero"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner is ready to execute test_divide_by_zero | - | PASS |
| 2 | Calls divide(10, 0) | Function divide is executing with a=10, b=0 | - | PASS |
| 3 | Raises ValueError with message 'Cannot divide by zero' | Exception is raised inside divide function | - | PASS |
| 4 | pytest.raises context captures the ValueError as exc_info | Exception info stored in exc_info variable | - | PASS |
| 5 | Assert exc_info.value.args[0] equals 'Cannot divide by zero' | Checking exception message content | Exception message is exactly 'Cannot divide by zero' | PASS |
| 6 | Test ends successfully | Test passed with no errors | - | PASS |