Skip to content

Commit b1c31a1

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

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Doc/library/unittest.mock.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,20 @@ object::
856856
3
857857
>>> p.assert_called_once_with()
858858

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

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

0 commit comments

Comments
 (0)