I am trying to dynamically mock/patch multiple @property methods of a class in python i.e.
class Dog():
...
@property
def size(self):
.....
@property
def breed(self):
.....
cases = [{"size":9, "breed":"doberman"}, {"size":2, "breed":"pug"}]
@pytest.mark.parametrize("case", list(cases.values()), ids=list(cases.keys()))
def test_properties(case):
dog = Dog()
mocks = ()
for m, v in case.items():
mocks += (mock.patch.object(dog, m, return_value=v),)
with mocks:
...
However, I get the following error:
with mocks:E AttributeError: enter
Clearly this is not the appropriate method of mocking multiple properties according to a config as shown above? Could someone please advise me on how to best achieve this, thanks!
cases.values()? it is a list of dict