-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
type: 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
I couldn't find this in previously opened tickets, so here goes: why don't we allow ids passed to pytest.mark.parametrize to be treated as format strings? It doesn't make much sense for those ids to be strings anyway as they would typically be either lists/iterables or callables.
E.g.:
# current
@pytest.mark.parametrize('foo', [1, 2, 3], ids=lambda x: f'foo:{x}') # either this
@pytest.mark.parametrize('bar', [0.1, 0.2, 0.3], ids='bar:{:.2%}'.format) # or this# proposed
@pytest.mark.parametrize('foo', [1, 2, 3], ids='foo:{}')
@pytest.mark.parametrize('bar', [0.1, 0.2, 0.3], ids='bar:{:.2%}')In the end, if ids is a callable, it's function that takes a single argument and converts it to a string.
One of the best built-in ways to do it in Python is via format strings, so why not provide direct ergonomic support for it?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: 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