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 |
@pytest.mark.parametrize in tests?@pytest.mark.parametrize decorator runs one test function multiple times with different input values.a and b in pytest?@pytest.mark.parametrize with a string of parameter names and a list of tuples for values.@pytest.mark.parametrize('a,b', [(1, 2), (3, 4)]). Others have wrong names or formats.import pytest
@pytest.mark.parametrize('x', [0, 1, 2])
@pytest.mark.parametrize('y', [10, 20])
def test_sum(x, y):
assert x + y > 10
@pytest.mark.parametrize('num', [1, 2, 3])
def test_is_even(num):
assert num % 2 == 0
@pytest.mark.parametrize decorators on a single test function affect test coverage and execution?Pass the test and this pattern moves unknown