I am using pytest3.7 to test. I would like to mock res
,which is return value from get_res_function
. res.property1[key1][keyN].property2
is the value I want to mock. Here is my test:
@mock.patch("mypkg.get_res_function")
def test_function(mock_res):
returner = mock.MagicMock()
returner.property1["key1"]["key2"].property2 = "11111"
returner.property1["key1"]["key3"].property2 = "22222"
mock_res.return_value = returner
However, both values i want to mock only use the first line mock's value, which means mock_res.property1["key1"]["key2"].property2 = "11111", mock_res_property1["key1"]["key3"].property2 = "11111"
and if reverse it in test code, meaning put "22222" before "11111",
returner.property1["key1"]["key2"].property2 = "22222"
returner.property1["key1"]["key3"].property2 = "11111"
then all the results is "22222", what is wrong?