-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
topic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrizetype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature
Description
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) == expectedbecomes:
@params(test_input=["3+5", "2+4"], expected=[8, 6])
def test_eval(test_input, expected):
assert eval(test_input) == expectedRelatedly, 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) == expectedReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
topic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrizetype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature