From aa612233728ddeada1d3dedff8528408999f67d0 Mon Sep 17 00:00:00 2001 From: KarnbirKhera <166065758+KarnbirKhera@users.noreply.github.com> Date: Sun, 9 Nov 2025 14:47:10 -0800 Subject: [PATCH 1/6] Refining some wording in unittest partial mock doc Some of the descriptions were addressed in first person, but have now been changed to address the user reading the documentation instead. --- Doc/library/unittest.mock-examples.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst index 00cc9bfc0a5f2b..3f796cf823fab2 100644 --- a/Doc/library/unittest.mock-examples.rst +++ b/Doc/library/unittest.mock-examples.rst @@ -600,12 +600,12 @@ this list of calls for us:: Partial mocking ~~~~~~~~~~~~~~~ -In some tests I wanted to mock out a call to :meth:`datetime.date.today` -to return a known date, but I didn't want to prevent the code under test from +For some tests you may want to mock out a call to :meth:`datetime.date.today` +to return a known date, but you may not want to prevent the code under test from creating new date objects. Unfortunately :class:`datetime.date` is written in C, and -so I couldn't just monkey-patch out the static :meth:`datetime.date.today` method. +so you cannot just monkey-patch out the static :meth:`datetime.date.today` method. -I found a simple way of doing this that involved effectively wrapping the date +A simple way of doing this involves effectively wrapping the date class with a mock, but passing through calls to the constructor to the real class (and returning real instances). From 97cc04ae42d1b73a244bcba9dd10013842bec71a Mon Sep 17 00:00:00 2001 From: KarnbirKhera <166065758+KarnbirKhera@users.noreply.github.com> Date: Sun, 9 Nov 2025 15:09:09 -0800 Subject: [PATCH 2/6] Update Doc/library/unittest.mock-examples.rst Co-authored-by: C.A.M. Gerlach --- Doc/library/unittest.mock-examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst index 3f796cf823fab2..3998e47cea1285 100644 --- a/Doc/library/unittest.mock-examples.rst +++ b/Doc/library/unittest.mock-examples.rst @@ -600,7 +600,7 @@ this list of calls for us:: Partial mocking ~~~~~~~~~~~~~~~ -For some tests you may want to mock out a call to :meth:`datetime.date.today` +For some tests, you may want to mock out a call to :meth:`datetime.date.today` to return a known date, but you may not want to prevent the code under test from creating new date objects. Unfortunately :class:`datetime.date` is written in C, and so you cannot just monkey-patch out the static :meth:`datetime.date.today` method. From 5c4f4c56b6f6b8edee6c6de0d25d5eeb5d021e24 Mon Sep 17 00:00:00 2001 From: KarnbirKhera <166065758+KarnbirKhera@users.noreply.github.com> Date: Sun, 9 Nov 2025 15:09:17 -0800 Subject: [PATCH 3/6] Update Doc/library/unittest.mock-examples.rst Co-authored-by: C.A.M. Gerlach --- Doc/library/unittest.mock-examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst index 3998e47cea1285..c2a938a02634e4 100644 --- a/Doc/library/unittest.mock-examples.rst +++ b/Doc/library/unittest.mock-examples.rst @@ -601,7 +601,7 @@ Partial mocking ~~~~~~~~~~~~~~~ For some tests, you may want to mock out a call to :meth:`datetime.date.today` -to return a known date, but you may not want to prevent the code under test from +to return a known date, but don't want to prevent the code under test from creating new date objects. Unfortunately :class:`datetime.date` is written in C, and so you cannot just monkey-patch out the static :meth:`datetime.date.today` method. From 602858c09c8dfff3a815a4f883ca8a16b301a74f Mon Sep 17 00:00:00 2001 From: KarnbirKhera <166065758+KarnbirKhera@users.noreply.github.com> Date: Sun, 9 Nov 2025 15:09:24 -0800 Subject: [PATCH 4/6] Update Doc/library/unittest.mock-examples.rst Co-authored-by: C.A.M. Gerlach --- Doc/library/unittest.mock-examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst index c2a938a02634e4..59d77c0fbd93a5 100644 --- a/Doc/library/unittest.mock-examples.rst +++ b/Doc/library/unittest.mock-examples.rst @@ -605,7 +605,7 @@ to return a known date, but don't want to prevent the code under test from creating new date objects. Unfortunately :class:`datetime.date` is written in C, and so you cannot just monkey-patch out the static :meth:`datetime.date.today` method. -A simple way of doing this involves effectively wrapping the date +Instead, you can effectively wrap the date class with a mock, but passing through calls to the constructor to the real class (and returning real instances). From 8eb1a2b00e98cefd095b81e62a166f7ba5223349 Mon Sep 17 00:00:00 2001 From: KarnbirKhera <166065758+KarnbirKhera@users.noreply.github.com> Date: Sun, 9 Nov 2025 15:09:31 -0800 Subject: [PATCH 5/6] Update Doc/library/unittest.mock-examples.rst Co-authored-by: C.A.M. Gerlach --- Doc/library/unittest.mock-examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst index 59d77c0fbd93a5..fad93654840b28 100644 --- a/Doc/library/unittest.mock-examples.rst +++ b/Doc/library/unittest.mock-examples.rst @@ -606,7 +606,7 @@ creating new date objects. Unfortunately :class:`datetime.date` is written in C, so you cannot just monkey-patch out the static :meth:`datetime.date.today` method. Instead, you can effectively wrap the date -class with a mock, but passing through calls to the constructor to the real +class with a mock, while passing through calls to the constructor to the real class (and returning real instances). The :func:`patch decorator ` is used here to From 41be6881dac91312995f92d498ba6981972384a0 Mon Sep 17 00:00:00 2001 From: KarnbirKhera <166065758+KarnbirKhera@users.noreply.github.com> Date: Sun, 9 Nov 2025 15:09:40 -0800 Subject: [PATCH 6/6] Update Doc/library/unittest.mock-examples.rst Co-authored-by: C.A.M. Gerlach --- Doc/library/unittest.mock-examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst index fad93654840b28..45200492afa1bb 100644 --- a/Doc/library/unittest.mock-examples.rst +++ b/Doc/library/unittest.mock-examples.rst @@ -602,7 +602,7 @@ Partial mocking For some tests, you may want to mock out a call to :meth:`datetime.date.today` to return a known date, but don't want to prevent the code under test from -creating new date objects. Unfortunately :class:`datetime.date` is written in C, and +creating new date objects. Unfortunately :class:`datetime.date` is written in C, so you cannot just monkey-patch out the static :meth:`datetime.date.today` method. Instead, you can effectively wrap the date