]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.12] gh-119600: mock: do not access attributes of original when new_callable is...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 11 Jun 2024 06:01:02 +0000 (08:01 +0200)
committerGitHub <noreply@github.com>
Tue, 11 Jun 2024 06:01:02 +0000 (06:01 +0000)
commitfa291a35eb29c53958aa5d2e2b58aea2441ffca8
tree3847b5b8058335533d3d0943317b90835c3df2c7
parenta9f2daf1ab182d95b44ee94dc9fb8faec60e34b1
[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 422c4fc855afd18bcc6415902ea1d85a50cb7ce1)

Co-authored-by: Robert Collins <robert.collins@cognite.com>
Lib/test/test_unittest/testmock/support.py
Lib/test/test_unittest/testmock/testpatch.py
Lib/unittest/mock.py
Misc/NEWS.d/next/Library/2024-06-10-14-00-40.gh-issue-119600.jJMf4C.rst [new file with mode: 0644]