Pytest: multiple mark.parametrize with tuples: `ValueError: indirect given to [...]`

Created on 30 Jun 2018  路  3Comments  路  Source: pytest-dev/pytest

Combining multiple mark.parametrize is easy. Just go

import pytest

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

However, this fails if one of the two parametrizations covers more than one argument. This

import pytest

@pytest.mark.parametrize('foo', 'bar', [('a', 1), ('b', 2), ('c', 3)])
@pytest.mark.parametrize('baz', [4, 5, 6])
def test_things(foo, bar, baz):
    assert foo in ['a', 'b', 'c']
    assert bar in [1, 2, 3]
    assert baz in [4, 5, 7]

fails with error

E   ValueError: indirect given to <function test_things at 0x7f3c2881e2f0>: fixture ('a', 1) doesn't exist

This is with

$ pytest --version
This is pytest version 3.6.2, imported from /path/to/pytest.py
parametrize bug

Most helpful comment

Ah, a typo.

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

should be

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

All 3 comments

GitMate.io thinks possibly related issues are https://github.com/pytest-dev/pytest/issues/815 (Combining multiple @pytest.mark.parametrize lines), https://github.com/pytest-dev/pytest/issues/1111 (pytest.mark.parametrize fails with lambdas), https://github.com/pytest-dev/pytest/issues/328 (@pytest.mark.parametrize not working with tuple as advertized in docs), https://github.com/pytest-dev/pytest/issues/2404 (Class decorator marks multiple classes), and https://github.com/pytest-dev/pytest/issues/213 (Issue with numpy arrays and pytest.mark.parametrize).

Ah, a typo.

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

should be

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

this deserves a followup since the triggered error is so missleading, i will open a issue

Was this page helpful?
0 / 5 - 0 ratings