Skip to content

Combining multiple @pytest.mark.parametrize lines #815

@The-Compiler

Description

@The-Compiler

I sometimes write tests something like this:

@pytest.mark.parametrize('foo, bar', itertools.product(['a', 'b', 'c'], [1, 2, 3]))
def test_things(foo, bar):
    ...

to test all combinations of foo and bar. The itertools.product call sometimes gets a bit more complicated which makes this hard to follow.

IMHO, it'd be nicer to be able to write those tests like this:

@pytest.mark.parametrize('foo', ['a', 'b'. 'c'])
@pytest.mark.parametrize('bar', [1, 2, 3])
def test_things(foo, bar):
    ...

And pytest would then generate all possible combinations. What are your thoughts on this?

I'm not sure if the difference between using two args in one parametrize call vs. using two parametrize calls with one argument each is too subtle, though.

Metadata

Metadata

Assignees

Labels

topic: parametrizerelated to @pytest.mark.parametrizetype: docsdocumentation improvement, missing or needing clarificationtype: 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