Skip to content

parameterize argvalues with a mapping #3588

Closed
@ikonst

Description

@ikonst

The current syntax for providing an id along with a parameter set is:

@pytest.mark.parameterize('a,b', [
    pytest.param(1, 3, id='odds'),
    pytest.param(2, 4, id='evens'),
])
def test_something(a, b):
    ...

I'd like to get peoples' opinions about an alternative syntax:

@pytest.mark.parameterize('a,b', {
    'odds': (1, 3),
    'evens': (2, 4),
})
def test_something(a, b):
    ...

The rationale, other than the alternative being shorter, is that (it seems to me) that mappings are natural for pairing identifiers and data. If we have to decide on a way to interpret someone passing a mapping into argvalues, I think that'll be a natural one.

P.S. currently, if you pass a dictionary as argvalues, its keys are iterated and the values are discarded

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: parametrizerelated to @pytest.mark.parametrizetype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions