I want to mock a property to return different values, in order, like when you use side_effect
on a Magic Mock. Right now I'm doing this:
mock = <my magic mock here>
type(mock).information = PropertyMock()
type(mock).information.side_effect = [1,2]
mock.information # it does not return 1
mock.information # it does not return 2
Any idea how to mock it properly?
CodePudding user response:
from unittest.mock import MagicMock, PropertyMock
m = MagicMock()
type(m).foo = PropertyMock(side_effect=[1, 2])
print(m.foo) # 1
print(m.foo) # 2