Open GoogleCodeExporter opened 9 years ago
Currently I'm working around this using the following code:
def add_property(mock_object, property_name, property_value) :
prop = mock.PropertyMock(return_value=property_value)
setattr(type(mock_object), property_name, prop)
mock_object.attach_mock(prop, property_name) # this fails if the property name isnt set
... but I'm not sure is this is the best way or not
Original comment by barcoded...@gmail.com
on 14 Nov 2013 at 3:24
So the problem is that using spec_set doesn't prevent you setting attributes on
the type. ProperyMock only works if you set it on the type.
I can't prevent you setting attributes on the type without a lot of complexity.
A better fix would be to allow you to set a PropertyMock directly on the
instance and have the mock automatically elevate it to the type. That would
then trigger the spec_set logic.
Original comment by fuzzyman
on 17 Nov 2013 at 11:53
Yep, that makes sense. Presumably the attach_mock method is a reasonable
workaround until then?
Original comment by barcoded...@gmail.com
on 18 Nov 2013 at 10:19
Yup, attach_mock is a good workaround.
Original comment by fuzzyman
on 18 Nov 2013 at 12:51
Original issue reported on code.google.com by
barcoded...@gmail.com
on 14 Nov 2013 at 11:32