PythiloLesson 4 of 12 · progress kept in this browser

Parametrize

When several tests differ only in their data, write the test once and hand pytest the cases. Each case runs as its own test with its own result, so one broken case does not hide the others, and the report names the case that failed, such as test_upper[ab-AB].

import pytest

@pytest.mark.parametrize("text, want", [
    ("ab", "AB"),
    ("", ""),
    pytest.param("ß", "SS", id="sharp-s"),
])
def test_upper(text, want):
    assert text.upper() == want, text

# Each case becomes one call:
test_upper("ab", "AB")
test_upper("ß", "SS")
print("cases pass")
Your task

is_leap(year) is written for you. Write one test, test_is_leap(year, want), parametrized with at least four cases, so that it fails if any leap-year rule is lost: every fourth year, except centuries, except every fourth century.

The first run loads pytest into this browser.