@@ -600,13 +600,13 @@ this list of calls for us::
600600Partial mocking
601601~~~~~~~~~~~~~~~
602602
603- In some tests I wanted to mock out a call to:meth: `datetime.date.today `
604- to return a known date, butI didn 't want to prevent the code under test from
605- creating new date objects. Unfortunately:class: `datetime.date ` is written in C, and
606- soI couldn't just monkey-patch out the static:meth: `datetime.date.today ` method.
603+ For some tests, you may want to mock out a call to:meth: `datetime.date.today `
604+ to return a known date, butdon 't want to prevent the code under test from
605+ creating new date objects. Unfortunately:class: `datetime.date ` is written in C,
606+ soyou cannot just monkey-patch out the static:meth: `datetime.date.today ` method.
607607
608- I found a simple way of doing this that involved effectivelywrapping the date
609- class with a mock,but passing through calls to the constructor to the real
608+ Instead, you can effectivelywrap the date
609+ class with a mock,while passing through calls to the constructor to the real
610610class (and returning real instances).
611611
612612The:func: `patch decorator <patch> ` is used here to
@@ -743,25 +743,24 @@ exception is raised in the setUp then tearDown is not called.
743743Mocking Unbound Methods
744744~~~~~~~~~~~~~~~~~~~~~~~
745745
746- Whilst writing tests today I needed to patch an *unbound method * (patching the
747- method on the class rather than on the instance). I needed self to be passed
748- in as the first argument because I want to make asserts about which objects
749- were calling this particular method. The issue is that you can't patch with a
750- mock for this, because if you replace an unbound method with a mock it doesn't
751- become a bound method when fetched from the instance, and so it doesn't get
752- self passed in. The workaround is to patch the unbound method with a real
753- function instead. The:func: `patch ` decorator makes it so simple to
754- patch out methods with a mock that having to create a real function becomes a
755- nuisance.
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
750+ 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 ``
752+ 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
754+ with a mock that having to create a real function becomes a nuisance.
756755
757756If you pass ``autospec=True `` to patch then it does the patching with a
758757*real * function object. This function object has the same signature as the one
759758it is replacing, but delegates to a mock under the hood. You still get your
760759mock auto-created in exactly the same way as before. What it means though, is
761760that if you use it to patch out an unbound method on a class the mocked
762761function will be turned into a bound method if it is fetched from an instance.
763- It will have ``self `` passed in as the first argument, which is exactly what I
764- wanted :
762+ It will have ``self `` passed in as the first argument, which is exactly what
763+ was needed :
765764
766765 >>>class Foo :
767766 ...def foo (self ):