-
-
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
As it is right now, to provide non-default test IDs when using pytest.mark.parametrize, one must use the ids keyword arg.
However, a thought occurred to me: What if we supply a dict to parametrize's argvalues, and from that dict, use the keys as the don-default test IDs?
For example, rather than:
@pytest.mark.parametrize(
"command", [
"RCPT",
"RCPT <anne@example.com>",
"RCPT TO:",
"RCPT TO: <bart@example.com> SIZE=1000",
],
ids=["noarg", "noto", "noaddr", "params"]
)we can supply it more succinctly like so:
@pytest.mark.parametrize(
"command", {
"noarg": "RCPT",
"noto": "RCPT <anne@example.com>",
"noaddr": "RCPT TO:",
"params": "RCPT TO: <bart@example.com> SIZE=1000",
}
)Users who absolutely need ordering can still use the first one, or use OrderedDict (or standard dict in Python>=3.7, where dict ordering became a language feature.)
senhalil
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