mirror of
https://github.com/python/cpython
synced 2024-10-14 23:49:42 +00:00
[3.12] gh-65454: avoid triggering call to a PropertyMock in NonCallableMock.__setattr__ (GH-120019) (#120337)
gh-65454: avoid triggering call to a PropertyMock in NonCallableMock.__setattr__ (GH-120019)
(cherry picked from commit 9e9ee50421
)
Co-authored-by: blhsing <blhsing@gmail.com>
This commit is contained in:
parent
fa291a35eb
commit
f6481925d8
|
@ -1127,6 +1127,14 @@ def test_propertymock_side_effect(self):
|
|||
p.assert_called_once_with()
|
||||
|
||||
|
||||
def test_propertymock_attach(self):
|
||||
m = Mock()
|
||||
p = PropertyMock()
|
||||
type(m).foo = p
|
||||
m.attach_mock(p, 'foo')
|
||||
self.assertEqual(m.mock_calls, [])
|
||||
|
||||
|
||||
class TestCallablePredicate(unittest.TestCase):
|
||||
|
||||
def test_type(self):
|
||||
|
|
|
@ -800,6 +800,9 @@ def __setattr__(self, name, value):
|
|||
mock_name = f'{self._extract_mock_name()}.{name}'
|
||||
raise AttributeError(f'Cannot set {mock_name}')
|
||||
|
||||
if isinstance(value, PropertyMock):
|
||||
self.__dict__[name] = value
|
||||
return
|
||||
return object.__setattr__(self, name, value)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
:func:`unittest.mock.Mock.attach_mock` no longer triggers a call to a ``PropertyMock`` being attached.
|
Loading…
Reference in a new issue