- 参数化多个参数:可以使用多个参数来参数化测试。例如:
import pytest
@pytest.mark.parametrize("x, y, expected", [
(1, 2, 3),
(3, 4, 7),
(5, 6, 11),
])
def test_addition(x, y, expected):
assert x + y == expected
- 参数化列表:可以使用列表来参数化测试。例如:
import pytest
@pytest.mark.parametrize("test_input, expected_output", [
([1, 2, 3], 6),
([4, 5, 6], 15),
([7, 8, 9], 24),
])
def test_sum(test_input