mirror of
https://github.com/python/cpython.git
synced 2025-08-19 08:11:46 +00:00
[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:
parent
a9f2daf1ab
commit
fa291a35eb
4 changed files with 29 additions and 5 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue