I have the below pytest script and the side_effect
value [2, 6]
is not getting iterated. It is always stuck with value 2
in the test function test_my_function
.
My question is:
How to make the side_effect
value iterate together with parametrize
test cases in function test_my_function
. (assume we must use parametrize
).
#!/usr/bin/env python3
#
import pytest
def my_function(x):
return x*2
@pytest.fixture
def mock_my_function(mocker):
mocker.patch(
__name__ + ".my_function", side_effect=[2, 6]
)
@pytest.mark.parametrize("input, expect", [(1, 2), (3, 6)])
def test_my_function(input, expect, mock_my_function):
assert expect == my_function(input)