]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] 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:04:06 +0000 (08:04 +0200)
committerGitHub <noreply@github.com>
Tue, 11 Jun 2024 06:04:06 +0000 (06:04 +0000)
commitaba5f2a4d10a7b261d4af03a54a8b1083bd83700
tree9a0f5010d55c7493a3ec9f51d44847dbc1e22590
parentffc8e21c80627c46be7a7467ee5427924fdeb885
[3.13] gh-119600: mock: do not access attributes of original when new_callable is set (GH-119601) (#120334)

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]