Skip to content

Commit 7f63241

Browse files
[3.13] gh-65453: Docs - clarify AttributeError behaviour on PropertyMock (GH-121666) (GH-121968)
Fixed at EuroPython 24 sprints. (cherry picked from commit 94e6644) Co-authored-by: Vlastimil Zíma <[email protected]>
1 parent d2caf8b commit 7f63241

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Doc/library/unittest.mock.rst

+14
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,20 @@ object::
860860
3
861861
>>> p.assert_called_once_with()
862862

863+
.. caution::
864+
865+
If an :exc:`AttributeError` is raised by :class:`PropertyMock`,
866+
it will be interpreted as a missing descriptor and
867+
:meth:`~object.__getattr__` will be called on the parent mock::
868+
869+
>>> m = MagicMock()
870+
>>> no_attribute = PropertyMock(side_effect=AttributeError)
871+
>>> type(m).my_property = no_attribute
872+
>>> m.my_property
873+
<MagicMock name='mock.my_property' id='140165240345424'>
874+
875+
See :meth:`~object.__getattr__` for details.
876+
863877

864878
.. class:: AsyncMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwargs)
865879

0 commit comments

Comments
 (0)