With this class:
class Something():
def __init__(self, name) -> None:
self.name=name
@property
def value(self):
# In real life, something long and complicated
return "no"
I would like to test it, and mock .value
to return .name
instead.
In my test function, I have:
def side_effect(side_self:Something):
return side_self.name
with patch.object(Something, "value", side_effect=side_effect, autospec=True):
...
Errors out because Something().value return a MagicMock
, not the str (name) I expect.
If instead I patch with (Something, "value", new_callable=PropertyMock, side_effect=side_effect
I get .side_effect() missing 1 required positional argument: 'side_self'
How can I mock value
to return name
?