]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-65453: Docs - clarify AttributeError behaviour on PropertyMock (GH-121666...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 19 Jul 2024 08:03:43 +0000 (10:03 +0200)
committerGitHub <noreply@github.com>
Fri, 19 Jul 2024 08:03:43 +0000 (10:03 +0200)
Fixed at EuroPython 24 sprints.
(cherry picked from commit 94e6644584d9cb08a4edcd1027e288386184816b)

Co-authored-by: Vlastimil Zíma <ziima@users.noreply.github.com>
Doc/library/unittest.mock.rst

index d8ba24c3146cf2b48318f4ef253cd4cddd6e6e52..2e0e062c64d8a40eb60cb5483ac17abfb4e176ff 100644 (file)
@@ -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
+        <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)