cpython/Lib/test/test_unittest/testmock/support.py
Robert Collins 422c4fc855
gh-119600: mock: do not access attributes of original when new_callable is set (#119601)
In order to patch flask.g e.g. as in #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.
2024-06-11 06:41:12 +01:00

27 lines
466 B
Python

target = {'foo': 'FOO'}
def is_instance(obj, klass):
"""Version of is_instance that doesn't access __class__"""
return issubclass(type(obj), klass)
class SomeClass(object):
class_attribute = None
def wibble(self): pass
class X(object):
pass
# A standin for weurkzeug.local.LocalProxy - issue 119600
def _inaccessible(*args, **kwargs):
raise AttributeError
class OpaqueProxy:
__getattribute__ = _inaccessible
g = OpaqueProxy()