Test Overview
This test checks that a function raises either a ValueError or a TypeError when given invalid inputs. It verifies that the function correctly handles multiple error cases.
This test checks that a function raises either a ValueError or a TypeError when given invalid inputs. It verifies that the function correctly handles multiple error cases.
import pytest def process_value(value): if not isinstance(value, int): raise TypeError("Value must be an integer") if value < 0: raise ValueError("Value must be non-negative") return value * 2 def test_process_value_exceptions(): with pytest.raises((ValueError, TypeError)) as exc_info: process_value(-1) # Should raise ValueError assert isinstance(exc_info.value, ValueError) with pytest.raises((ValueError, TypeError)) as exc_info: process_value('a') # Should raise TypeError assert isinstance(exc_info.value, TypeError)
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | - | PASS |
| 2 | Calls process_value(-1) | Function receives -1 as input | Check if ValueError or TypeError is raised | PASS |
| 3 | process_value raises ValueError("Value must be non-negative") | Exception raised inside function | Exception type is ValueError | PASS |
| 4 | Assertion confirms exception is ValueError | Exception captured in exc_info | assert isinstance(exc_info.value, ValueError) | PASS |
| 5 | Calls process_value('a') | Function receives string 'a' as input | Check if ValueError or TypeError is raised | PASS |
| 6 | process_value raises TypeError("Value must be an integer") | Exception raised inside function | Exception type is TypeError | PASS |
| 7 | Assertion confirms exception is TypeError | Exception captured in exc_info | assert isinstance(exc_info.value, TypeError) | PASS |
| 8 | Test ends | All assertions passed | - | PASS |