Author stevenk
Recipients eric.snow, kushal.das, michael.foord, rbcollins, stevenk
Date 2016-09-12.03:23:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1473650583.81.0.580666393455.issue21254@psf.upfronthosting.co.za>
In-reply-to
Content
This is in fact, working entirely as expected.

If we define a property that raises an AttributeError, then __getattr__() will be called, since the descriptor protocol says that an attribute error is a missing descriptor.

>>> class Foo(object):
...   def __getattr__(self, attr):
...     return 42
...   @property
...   def bacon(self):
...     print(1)
...     return int.lala
... 
>>> Foo().bacon
1
42

If we then follow a similar pattern using mock:

>>> from unittest import mock
>>> a_mock = mock.MagicMock()
>>> def foo():
...   print(1)
...   raise AttributeError()
... 
>>> no_attribute = mock.PropertyMock(side_effect=foo)
>>> type(a_mock).property = no_attribute
>>> a_mock.property
1
<MagicMock name='mock.property' id='139971099507232'>

You can see that the method is called, since we print one, but then what is going on is that MagicMock.__getattr__ is called, which has the behavior to return a new mock, like so:

>>> a_mock.b
<MagicMock name='mock.b' id='139971099646776'>
History
Date User Action Args
2016-09-12 03:23:03stevenksetrecipients: + stevenk, rbcollins, michael.foord, eric.snow, kushal.das
2016-09-12 03:23:03stevenksetmessageid: <1473650583.81.0.580666393455.issue21254@psf.upfronthosting.co.za>
2016-09-12 03:23:03stevenklinkissue21254 messages
2016-09-12 03:23:03stevenkcreate