gh-62480: De-personalize "Partial mocking" section in unittest.mock examples (#141321)

* Refine 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.

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
This commit is contained in:
KarnbirKhera 2025-11-09 15:45:38 -08:00 committed by GitHub
parent ec85d3cbfe
commit b618731781
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -600,13 +600,13 @@ this list of calls for us::
Partial mocking Partial mocking
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
In some tests I wanted 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 I didn't 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 creating new date objects. Unfortunately :class:`datetime.date` is written in C,
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 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). class (and returning real instances).
The :func:`patch decorator <patch>` is used here to The :func:`patch decorator <patch>` is used here to