Proposal to enhance parametrize with support for keyword params. This seems more pythonic than the zipped format, for simple params. Reference implementation (under a different name):
def params(**kwargs):
if len(kwargs) == 1:
return pytest.mark.parametrize(*kwargs.popitem())
return pytest.mark.parametrize(','.join(kwargs), zip(*kwargs.values()))
An example from the docs:
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
])
def test_eval(test_input, expected):
assert eval(test_input) == expected
becomes:
@params(test_input=["3+5", "2+4"], expected=[8, 6])
def test_eval(test_input, expected):
assert eval(test_input) == expected
Relatedly, it also seems a perfect use case for Python 3 annotations:
def parametrized(func):
return params(**func.__annotations__)(func)
@parametrized
def test_eval(test_input: ["3+5", "2+4"], expected: [8, 6]):
assert eval(test_input) == expected
Proposal to enhance
parametrizewith support for keyword params. This seems more pythonic than the zipped format, for simple params. Reference implementation (under a different name):An example from the docs:
becomes:
Relatedly, it also seems a perfect use case for Python 3 annotations: