From fdaac25dc66964825412a67e1681f36a686413fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Z=C3=ADma?= Date: Sat, 13 Jul 2024 11:09:13 +0200 Subject: [PATCH 1/2] gh-65453: Docs - clarify AttributeError behaviour on PropertyMock Fixed at EuroPython 24 sprints. --- Doc/library/unittest.mock.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index d8ba24c3146cf2..6b31940c1ae667 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -860,6 +860,18 @@ object:: 3 >>> p.assert_called_once_with() +.. caution:: + + If an :exc:`AttributeError` is to be raised by :class:`PropertyMock`, it will be interpreted as a missing descriptor and following :meth:`__getattr__` call 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) From 013b8798f19440f604a3e6f7602fff0d30a1006f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Z=C3=ADma?= Date: Sat, 13 Jul 2024 16:15:30 +0200 Subject: [PATCH 2/2] fixup! Reformat the text output of unittest Co-authored-by: Petr Viktorin --- Doc/library/unittest.mock.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 6b31940c1ae667..2e0e062c64d8a4 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -862,7 +862,9 @@ object:: .. caution:: - If an :exc:`AttributeError` is to be raised by :class:`PropertyMock`, it will be interpreted as a missing descriptor and following :meth:`__getattr__` call will be called on the parent mock. :: + 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)