pytest-parametrized icon indicating copy to clipboard operation
pytest-parametrized copied to clipboard

`parametrized` doesn't work properly with `pytest.param`

Open mathrick opened this issue 1 year ago • 3 comments

If any of the values passed in are wrapped in pytest.param, the resulting values are not properly unpacked with @parametrized and thus change what the test actually receives.

Repro example:

import pytest
from parametrized import parametrized

VALUES1 = [
    "foo",
]

VALUES2 = [
    "foo",
    pytest.param("baz", marks=pytest.mark.xfail(reason="it's different")),
]

@pytest.mark.parametrize("arg1", VALUES1)
@pytest.mark.parametrize("arg2", VALUES2)
def test_plain(arg1, arg2):
    assert arg1 == arg2

@parametrized.product
def test_parametrized(arg1=VALUES1, arg2=VALUES2):
    assert arg1 == arg2

Result:

============================================================== FAILURES ===============================================================
____________________________________________________ test_parametrized[arg21-foo] _____________________________________________________

arg1 = 'foo'
arg2 = ParameterSet(values=('baz',), marks=(MarkDecorator(mark=Mark(name='xfail', args=(), kwargs={'reason': "it's different"})),), id=None)

    @parametrized.product
    def test_parametrized(arg1=VALUES1, arg2=VALUES2):
>       assert arg1 == arg2
E       assert 'foo' == ParameterSet(values=('baz',), marks=(MarkDecorator(mark=Mark(name='xfail', args=(), kwargs={'reason': "it's different"})),), id=None)

/tmp/test.py:20: AssertionError

mathrick avatar Oct 04 '24 20:10 mathrick