Repaso
Español
TestingCoreTST-02

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 == expected

Options

  1. 1
  2. 3 (Correct option)
  3. 6
  4. 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.

Key terms

Practice this question in Repaso