[3.12] gh-119600: mock: do not access attributes of original when new_callable is set (GH-119601) (#120335)

gh-119600: mock: do not access attributes of original when new_callable is set (GH-119601)

In order to patch flask.g e.g. as in GH-84982, that
proxies getattr must not be invoked. For that,
mock must not try to read from the original
object. In some cases that is unavoidable, e.g.
when doing autospec. However, patch("flask.g",
new_callable=MagicMock) should be entirely safe.
(cherry picked from commit 422c4fc855)

Co-authored-by: Robert Collins <robert.collins@cognite.com>
This commit is contained in:
Miss Islington (bot) 2024-06-11 08:01:02 +02:00 committed by GitHub
parent a9f2daf1ab
commit fa291a35eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 5 deletions

View file

@ -14,3 +14,14 @@ class SomeClass(object):
class X(object):
pass
# A standin for weurkzeug.local.LocalProxy - issue 119600
def _inaccessible(*args, **kwargs):
raise AttributeError
class OpaqueProxy:
__getattribute__ = _inaccessible
g = OpaqueProxy()