I have a function that runs some code if the object has a certain attribute, and in rare cases if if the object does not have the attribute, it runs different code. It is hard for me to create the object without the attribute for testing. I tried del instance.attribute
but got an error. The attribute is actually a @property
under the hood.
I have an object instance
that has foo
attribute. How does one mock it so that when one tries to access instance.foo
it raises an AttributeError
as usual if there is no attribute?
I tried mock.Mock(side_effect=AttributeError('Boom!'))
but it only works with methods.