I have a project that I need to mock a property using the mocker
fixture. Its using pytest and pytest-mock:
pip install pytest pytest-mock
A simple example of the problem:
I have the foo
class in the foo.py file:
class Foo:
@property
def bar(self):
return "x"
And I have to test it mocking the property bar
:
import foo
def test_foo(mocker):
mocker.patch("foo.Foo.bar", return_value="y")
f = foo.Foo()
assert f.bar == "y"
But when I patch it, the bar behaves like a callable and not like an attribute, how to fix this?