Skip to content

Allow parametrize ids to accept generators #759

Closed
@pytestbot

Description

@pytestbot

Originally reported by: Ivan Smirnov (BitBucket: aldanor, GitHub: aldanor)


Is it too restrictive to assert that ids in Metafunc.parametrize must always have length? It might be more Pythonic to try and create a list of len(argvalues) elements out of ids first:

...
        idfn = None
        if callable(ids):
            idfn = ids
            ids = None
        if ids and len(ids) != len(argvalues):
            raise ValueError('%d tests specified with %d ids' %(
                             len(argvalues), len(ids)))
...

An example use case could be something like this (enumerate the parametrized tests):

@pytest.mark.parametrize('param', ['foo', 'bar', 'baz'], ids=itertools.count())
def some_test(x):
    # ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: parametrizerelated to @pytest.mark.parametrizetype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions