This works
import pytest
@pytest.mark.parametrize( "expected",
[
pytest.param(42, marks=pytest.mark.xfail(reason="some bug")),
],)
def test_func(expected):
assert 123 == expected
output is
test_xfail_demo_1.py::test_func[42] XFAIL (some bug)
========== 1 xfailed in 0.07s ==========
but this one does not
import pytest
def someFunc():
return 1
def someOtherFunc():
return 123
@pytest.mark.parametrize( "expected",
[
(1, pytest.param(42, marks=pytest.mark.xfail(reason="some bug"))),
],)
def test_func(expected):
assert someFunc() == expected[0]
assert someOtherFunc() == expected[1]
The error I got is
> assert someOtherFunc() == expected[1]
E AssertionError: assert 123 == ParameterSet(values=(42,),
marks=(MarkDecorator(mark=Mark(name='xfail', args=(), kwargs={'reason': 'some bug'})),), id=None)
path/to/test_xfail_demo_2.py:10: AssertionError
==================== short test summary info ===============
FAILED path/to/test_xfail_demo_2.py::test_func[expected0] - AssertionError: assert 123 == ParameterSet(values=(42,), marks=(MarkDecorator(mark=Mark(name='xfail', args=(), kwargs={'reason': 'some bug'})),), id=None)
============== 1 failed in 0.09s =====
The reason I want expected to be a tuple is because I have multiple assert in a single test function, and I want to pass in all the expected values as a tuple or list, but mark only some of the list elements to be xfail or skip.