Test Overview
This test uses pytest's parametrize feature to run the same test logic with different inputs. It verifies that the function correctly identifies even numbers for multiple cases, increasing test coverage efficiently.
This test uses pytest's parametrize feature to run the same test logic with different inputs. It verifies that the function correctly identifies even numbers for multiple cases, increasing test coverage efficiently.
import pytest def is_even(num): return num % 2 == 0 @pytest.mark.parametrize("input_num,expected", [ (2, True), (3, False), (0, True), (-4, True), (7, False) ]) def test_is_even(input_num, expected): assert is_even(input_num) == expected
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts with input_num=2 and expected=True | Test environment ready, function is_even loaded | Check if is_even(2) == True | PASS |
| 2 | Test runs with input_num=3 and expected=False | Same test function reused with new parameters | Check if is_even(3) == False | PASS |
| 3 | Test runs with input_num=0 and expected=True | Test function called again with zero input | Check if is_even(0) == True | PASS |
| 4 | Test runs with input_num=-4 and expected=True | Negative even number tested | Check if is_even(-4) == True | PASS |
| 5 | Test runs with input_num=7 and expected=False | Odd number tested last | Check if is_even(7) == False | PASS |