Test Overview
This test checks a function that adds two numbers. It uses multiple parameters to test different pairs of numbers and verifies the sum is correct.
This test checks a function that adds two numbers. It uses multiple parameters to test different pairs of numbers and verifies the sum is correct.
import pytest @pytest.mark.parametrize("a,b,expected", [ (1, 2, 3), (5, 5, 10), (10, -2, 8), (0, 0, 0) ]) def test_addition(a, b, expected): result = a + b assert result == expected, f"Expected {expected} but got {result}"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | — | PASS |
| 2 | Test runner reads @pytest.mark.parametrize with parameters (a,b,expected) | Test cases prepared for each parameter set | — | PASS |
| 3 | Test case 1 runs with a=1, b=2, expected=3 | Function adds 1 + 2 | Check if result == 3 | PASS |
| 4 | Test case 2 runs with a=5, b=5, expected=10 | Function adds 5 + 5 | Check if result == 10 | PASS |
| 5 | Test case 3 runs with a=10, b=-2, expected=8 | Function adds 10 + (-2) | Check if result == 8 | PASS |
| 6 | Test case 4 runs with a=0, b=0, expected=0 | Function adds 0 + 0 | Check if result == 0 | PASS |
| 7 | All parameterized tests complete | Test report generated with all passes | — | PASS |
@pytest.mark.parametrize with multiple parameters in pytest?@pytest.mark.parametrizea and b in pytest?import pytest
@pytest.mark.parametrize('x, y', [(1, 2), (3, 4)])
def test_sum(x, y):
assert x + y == 33 == 3 passes.7 == 3 fails.import pytest
@pytest.mark.parametrize('a, b', [1, 2, 3])
def test_multiply(a, b):
assert a * b > 0is_even_sum(a, b) that returns True if the sum of a and b is even. Which @pytest.mark.parametrize setup with a single decorator correctly tests all combinations of a from [1, 2] and b from [3, 4] respectively?@pytest.mark.parametrize('a, b', [(1, 3), (1, 4), (2, 3), (2, 4)]) lists all pairs explicitly: (1,3), (1,4), (2,3), (2,4).Pass the test and this pattern moves unknown