I'm using MagicMock with Python 2.7 to mock objects. One of the classes that I'm mocking has properties, one of which can raise a TypeError
in some cases.
I would like to mock that behavior, but I can't figure out how:
del my_mock.my_property
will cause anAttributeError
ifmy_property
is accessed, but I need aTypeError
.my_mock.my_property = MagicMock(side_effect=TypeError)
causes aTypeError
whenmy_property
is called, but not when it's merely accessed.
How would I do that?