From 8303d32ff55945c5b38eeeaf1b1811dbcf8aa9be Mon Sep 17 00:00:00 2001 From: Dominic H Date: Mon, 15 Jul 2024 09:14:17 +0200 Subject: [PATCH] gh-117765: Improve documentation for `mocker.patch.dict` (#121755) --- Doc/library/unittest.mock.rst | 3 ++- Lib/unittest/mock.py | 3 ++- .../2024-07-14-12-25-53.gh-issue-117765.YFMOUv.rst | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Documentation/2024-07-14-12-25-53.gh-issue-117765.YFMOUv.rst diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index d8ba24c3146..01206e05f4b 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1624,7 +1624,8 @@ patch.dict .. function:: patch.dict(in_dict, values=(), clear=False, **kwargs) Patch a dictionary, or dictionary like object, and restore the dictionary - to its original state after the test. + to its original state after the test, where the restored dictionary is a + copy of the dictionary as it was before the test. *in_dict* can be a dictionary or a mapping like container. If it is a mapping then it must at least support getting, setting and deleting items diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index d50535dffeb..2bbbcf40e21 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1829,7 +1829,8 @@ def patch( class _patch_dict(object): """ Patch a dictionary, or dictionary like object, and restore the dictionary - to its original state after the test. + to its original state after the test, where the restored dictionary is + a copy of the dictionary as it was before the test. `in_dict` can be a dictionary or a mapping like container. If it is a mapping then it must at least support getting, setting and deleting items diff --git a/Misc/NEWS.d/next/Documentation/2024-07-14-12-25-53.gh-issue-117765.YFMOUv.rst b/Misc/NEWS.d/next/Documentation/2024-07-14-12-25-53.gh-issue-117765.YFMOUv.rst new file mode 100644 index 00000000000..a727c1aa9a0 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2024-07-14-12-25-53.gh-issue-117765.YFMOUv.rst @@ -0,0 +1 @@ +Improved documentation for :func:`unittest.mock.patch.dict`