From f5419dbf1d03a43c1187928fe436afd40affd78b Mon Sep 17 00:00:00 2001 From: Dominic H Date: Sun, 14 Jul 2024 12:27:04 +0200 Subject: [PATCH 1/3] Improve documentation for `mocker.patch.dict` --- 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 d8ba24c3146cf2..814f6799894365 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 the + 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 d50535dffeb5d1..71109854c6bd85 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 + the 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 00000000000000..01f9461bfc3b6e --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2024-07-14-12-25-53.gh-issue-117765.YFMOUv.rst @@ -0,0 +1 @@ +Improve documentation for :func:`unittest.mock.patch_dict` From 178dfd0de19e2185e3469ca26e009ccd51df1219 Mon Sep 17 00:00:00 2001 From: Dominic H Date: Sun, 14 Jul 2024 12:48:20 +0200 Subject: [PATCH 2/3] Fix news blurb --- .../2024-07-14-12-25-53.gh-issue-117765.YFMOUv.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 01f9461bfc3b6e..be66900845c462 100644 --- 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 @@ -1 +1 @@ -Improve documentation for :func:`unittest.mock.patch_dict` +Improve documentation for :func:`unittest.mock.patch.dict` From f5113da00bef457ca3989d2737cc36efc7dc4b04 Mon Sep 17 00:00:00 2001 From: Dominic H Date: Mon, 15 Jul 2024 08:47:15 +0200 Subject: [PATCH 3/3] Address nitpicks --- Doc/library/unittest.mock.rst | 2 +- Lib/unittest/mock.py | 2 +- .../2024-07-14-12-25-53.gh-issue-117765.YFMOUv.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 814f6799894365..01206e05f4ba01 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1624,7 +1624,7 @@ 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, where the restored dictionary is the + 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 diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 71109854c6bd85..2bbbcf40e21543 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1830,7 +1830,7 @@ class _patch_dict(object): """ Patch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test, where the restored dictionary is - the copy of the dictionary as it was before the test. + 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 index be66900845c462..a727c1aa9a0571 100644 --- 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 @@ -1 +1 @@ -Improve documentation for :func:`unittest.mock.patch.dict` +Improved documentation for :func:`unittest.mock.patch.dict`