Complete worked example
python
import pytest
def clean_name(value):
return value.strip()
@pytest.mark.parametrize("raw, expected", [
pytest.param(" Ada ", "Ada", id="padded"),
pytest.param("Ada", "Ada", id="already-clean"),
])
def test_clean_name(raw, expected):
assert clean_name(raw) == expected- Reasoning
- pytest.mark.parametrize supplies arguments by the names in its first string. The test function receives the corresponding row values. The worked example runs the same assertion twice, and IDs identify padded and already-clean inputs. Each parameter row is a separate collected test item. The expected column stays literal: it is not computed by calling strip again. This separates the specification from the implementation. Keep the number and order of parameter names aligned with each row; a collection error is different from a failed test body.