Parameterised tests in Python

Python

One test body, many cases, and a failure that names the case that broke.

import pytest

@pytest.mark.parametrize('raw,expected', [
    ('1',    1),
    ('  2 ', 2),
    ('0',    None),
    ('abc',  None),
])
def test_parse_page(raw, expected):
    assert parse_page(raw) == expected

More in Testing

Random picks