mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
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.
This commit is contained in:
parent
6efe346069
commit
422c4fc855
4 changed files with 29 additions and 5 deletions
|
|
@ -2045,6 +2045,13 @@ def test(): pass
|
|||
with self.assertRaises(TypeError):
|
||||
test()
|
||||
|
||||
def test_patch_proxy_object(self):
|
||||
@patch("test.test_unittest.testmock.support.g", new_callable=MagicMock())
|
||||
def test(_):
|
||||
pass
|
||||
|
||||
test()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue