How many test cases does pytest run here?
import pytest
@pytest.mark.parametrize("a,b,expected", [
(1, 2, 3),
(0, 0, 0),
(-1, 1, 0),
])
def test_add(a, b, expected):
assert a + b == expectedOptions
- 1
- 3 (Correct option)
- 6
- 9
Answer
3
Why
parametrize runs the same test function once for each set of values in the list. Three tuples → three separate test cases, each reported as passed or failed on its own.
This avoids copy-pasting nearly identical tests, and one failing input does not hide the others.
Remember
parametrize = same test, many inputs.