From: Vlastimil Zíma Date: Thu, 18 Jul 2024 13:57:21 +0000 (+0200) Subject: gh-65453: Docs - clarify AttributeError behaviour on PropertyMock (GH-121666) X-Git-Tag: v3.14.0a1~1072 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=94e6644584d9cb08a4edcd1027e288386184816b;p=thirdparty%2FPython%2Fcpython.git gh-65453: Docs - clarify AttributeError behaviour on PropertyMock (GH-121666) Fixed at EuroPython 24 sprints. --- diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 01206e05f4ba..757277e102d8 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -860,6 +860,20 @@ object:: 3 >>> p.assert_called_once_with() +.. caution:: + + If an :exc:`AttributeError` is raised by :class:`PropertyMock`, + it will be interpreted as a missing descriptor and + :meth:`~object.__getattr__` will be called on the parent mock:: + + >>> m = MagicMock() + >>> no_attribute = PropertyMock(side_effect=AttributeError) + >>> type(m).my_property = no_attribute + >>> m.my_property + + + See :meth:`~object.__getattr__` for details. + .. class:: AsyncMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwargs)