Skip to content

Commit 5cf5edc

Browse files
oklenaCAM-Gerlachpicnixz
authored
Apply suggestions from code review
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 687bd3f commit 5cf5edc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Doc/library/unittest.mock-examples.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -743,14 +743,14 @@ exception is raised in the setUp then tearDown is not called.
743743
Mocking Unbound Methods
744744
~~~~~~~~~~~~~~~~~~~~~~~
745745

746-
Sometimes a test needs to patch an *unbound method* which means patching the
747-
method on the class rather than on the instance. In order to make asserts
748-
about which objects were calling this particular method, you need to pass
749-
self as the first argument. The issue is that you can't patch with a mock for
746+
Sometimes a test needs to patch an *unbound method*, which means patching the
747+
method on the class rather than on the instance. In order to make assertions
748+
about which objects were calling this particular method, you need to pass
749+
``self`` as the first argument. The issue is that you can't patch with a mock for
750750
this, because if you replace an unbound method with a mock it doesn't become
751-
a bound method when fetched from the instance, and so it doesn't get self
751+
a bound method when fetched from the instance, and so it doesn't get ``self``
752752
passed in. The workaround is to patch the unbound method with a real function
753-
instead. The :func:`patch` decorator makes it so simple to patch out methods
753+
instead. The :func:`patch` decorator makes it so simple to patch out methods
754754
with a mock that having to create a real function becomes a nuisance.
755755

756756
If you pass ``autospec=True`` to patch then it does the patching with a
@@ -759,7 +759,7 @@ it is replacing, but delegates to a mock under the hood. You still get your
759759
mock auto-created in exactly the same way as before. What it means though, is
760760
that if you use it to patch out an unbound method on a class the mocked
761761
function will be turned into a bound method if it is fetched from an instance.
762-
It will have ``self`` passed in as the first argument, which is exactly what
762+
It will have ``self`` passed in as the first argument, which is exactly what
763763
was needed:
764764

765765
>>> class Foo:

0 commit comments

Comments
 (0)