https://github.com/python/cpython/commit/b1c31a1547106668897b9a87d051dc942f33cdef
commit: b1c31a1547106668897b9a87d051dc942f33cdef
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: encukou <[email protected]>
date: 2024-07-19T10:03:54+02:00
summary:

[3.12] gh-65453: Docs - clarify AttributeError behaviour on PropertyMock 
(GH-121666) (GH-121969)

Fixed at EuroPython 24 sprints.
(cherry picked from commit 94e6644584d9cb08a4edcd1027e288386184816b)

Co-authored-by: Vlastimil Zíma <[email protected]>

files:
M Doc/library/unittest.mock.rst

diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst
index 8dcb8c2aa547b5..1fbef02a2c69a1 100644
--- a/Doc/library/unittest.mock.rst
+++ b/Doc/library/unittest.mock.rst
@@ -856,6 +856,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
+        <MagicMock name='mock.my_property' id='140165240345424'>
+
+    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)
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to