@@ -68,7 +68,7 @@ available, and then make assertions about how they have been used:
6868 3
6969 >>> thing.method.assert_called_with(3 , 4 , 5 , key = ' value' )
7070
71- :attr: `side_effect ` allows you to perform side effects, including raising an
71+ :attr: `~Mock. side_effect ` allows you to perform side effects, including raising an
7272exception when a mock is called:
7373
7474 >>> from unittest.mock import Mock
@@ -760,16 +760,16 @@ the *new_callable* argument to :func:`patch`.
760760
761761 .. attribute :: __class__
762762
763- Normally the :attr: `__class__ ` attribute of an object will return its type.
764- For a mock object with a :attr: `spec `, `` __class__ ` ` returns the spec class
763+ Normally the :attr: `! __class__ ` attribute of an object will return its type.
764+ For a mock object with a :attr: `! spec `, :attr: ` ! __class__ ` returns the spec class
765765 instead. This allows mock objects to pass :func: `isinstance ` tests for the
766766 object they are replacing / masquerading as:
767767
768768 >>> mock = Mock(spec = 3 )
769769 >>> isinstance (mock, int )
770770 True
771771
772- :attr: `__class__ ` is assignable to, this allows a mock to pass an
772+ :attr: `! __class__ ` is assignable to, this allows a mock to pass an
773773 :func: `isinstance ` check without forcing you to use a spec:
774774
775775 >>> mock = Mock()
@@ -783,8 +783,8 @@ the *new_callable* argument to :func:`patch`.
783783 meaning of :class: `Mock `, with the exception of *return_value * and *side_effect *
784784 which have no meaning on a non-callable mock.
785785
786- Mock objects that use a class or an instance as a :attr: `spec ` or
787- :attr: `spec_set ` are able to pass :func: `isinstance ` tests:
786+ Mock objects that use a class or an instance as a :attr: `! spec ` or
787+ :attr: `! spec_set ` are able to pass :func: `isinstance ` tests:
788788
789789 >>> mock = Mock(spec = SomeClass)
790790 >>> isinstance (mock, SomeClass)
@@ -1198,7 +1198,7 @@ Calls made to the object will be recorded in the attributes
11981198like :attr: `~Mock.call_args ` and :attr: `~Mock.call_args_list `.
11991199
12001200If :attr: `~Mock.side_effect ` is set then it will be called after the call has
1201- been recorded, so if :attr: `side_effect ` raises an exception the call is still
1201+ been recorded, so if :attr: `! side_effect ` raises an exception the call is still
12021202recorded.
12031203
12041204The simplest way to make a mock raise an exception when called is to make
@@ -1219,8 +1219,8 @@ The simplest way to make a mock raise an exception when called is to make
12191219 >>> m.mock_calls
12201220 [call(1, 2, 3), call('two', 'three', 'four')]
12211221
1222- If :attr: `side_effect ` is a function then whatever that function returns is what
1223- calls to the mock return. The :attr: `side_effect ` function is called with the
1222+ If :attr: `~Mock. side_effect ` is a function then whatever that function returns is what
1223+ calls to the mock return. The :attr: `! side_effect ` function is called with the
12241224same arguments as the mock. This allows you to vary the return value of the
12251225call dynamically, based on the input:
12261226
@@ -1237,7 +1237,7 @@ call dynamically, based on the input:
12371237
12381238If you want the mock to still return the default return value (a new mock), or
12391239any set return value, then there are two ways of doing this. Either return
1240- :attr: `mock .return_value ` from inside :attr: `side_effect `, or return :data: `DEFAULT `:
1240+ :attr: `~Mock .return_value ` from inside :attr: `~Mock. side_effect `, or return :data: `DEFAULT `:
12411241
12421242 >>> m = MagicMock()
12431243 >>> def side_effect (* args , ** kwargs ):
@@ -1254,8 +1254,8 @@ any set return value, then there are two ways of doing this. Either return
12541254 >>> m()
12551255 3
12561256
1257- To remove a :attr: `side_effect `, and return to the default behaviour, set the
1258- :attr: `side_effect ` to ``None ``:
1257+ To remove a :attr: `~Mock. side_effect `, and return to the default behaviour, set the
1258+ :attr: `! side_effect ` to ``None ``:
12591259
12601260 >>> m = MagicMock(return_value = 6 )
12611261 >>> def side_effect (* args , ** kwargs ):
@@ -1268,7 +1268,7 @@ To remove a :attr:`side_effect`, and return to the default behaviour, set the
12681268 >>> m()
12691269 6
12701270
1271- The :attr: `side_effect ` can also be any iterable object. Repeated calls to the mock
1271+ The :attr: `~Mock. side_effect ` can also be any iterable object. Repeated calls to the mock
12721272will return values from the iterable (until the iterable is exhausted and
12731273a :exc: `StopIteration ` is raised):
12741274
@@ -1309,7 +1309,7 @@ objects of any type.
13091309
13101310You may want a mock object to return ``False `` to a :func: `hasattr ` call, or raise an
13111311:exc: `AttributeError ` when an attribute is fetched. You can do this by providing
1312- an object as a :attr: `spec ` for a mock, but that isn't always convenient.
1312+ an object as a :attr: `! spec ` for a mock, but that isn't always convenient.
13131313
13141314You "block" attributes by deleting them. Once deleted, accessing an attribute
13151315will raise an :exc: `AttributeError `.
@@ -1478,7 +1478,7 @@ patch
14781478 If you are patching builtins in a module then you don't
14791479 need to pass ``create=True ``, it will be added by default.
14801480
1481- Patch can be used as a :class: `TestCase ` class decorator. It works by
1481+ Patch can be used as a :class: `~unittest. TestCase ` class decorator. It works by
14821482 decorating each test method in the class. This reduces the boilerplate
14831483 code when your test methods share a common patchings set. :func: `patch ` finds
14841484 tests by looking for method names that start with ``patch.TEST_PREFIX ``.
@@ -1516,7 +1516,7 @@ If the class is instantiated multiple times you could use
15161516can set the *return_value * to be anything you want.
15171517
15181518To configure return values on methods of *instances * on the patched class
1519- you must do this on the :attr: `return_value `. For example::
1519+ you must do this on the :attr: `~Mock. return_value `. For example::
15201520
15211521 >>> class Class:
15221522 ... def method(self):
@@ -1838,13 +1838,13 @@ context manager is a dictionary where created mocks are keyed by name::
18381838patch methods: start and stop
18391839~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18401840
1841- All the patchers have :meth: `start ` and :meth: `stop ` methods. These make it simpler to do
1841+ All the patchers have :meth: `! start ` and :meth: `! stop ` methods. These make it simpler to do
18421842patching in ``setUp `` methods or where you want to do multiple patches without
18431843nesting decorators or with statements.
18441844
18451845To use them call :func: `patch `, :func: `patch.object ` or :func: `patch.dict ` as
18461846normal and keep a reference to the returned ``patcher `` object. You can then
1847- call :meth: `start ` to put the patch in place and :meth: `stop ` to undo it.
1847+ call :meth: `! start ` to put the patch in place and :meth: `! stop ` to undo it.
18481848
18491849If you are using :func: `patch ` to create a mock for you then it will be returned by
18501850the call to ``patcher.start ``. ::
@@ -1861,7 +1861,7 @@ the call to ``patcher.start``. ::
18611861
18621862
18631863A typical use case for this might be for doing multiple patches in the ``setUp ``
1864- method of a :class: `TestCase `::
1864+ method of a :class: `~unittest. TestCase `::
18651865
18661866 >>> class MyTest(unittest.TestCase):
18671867 ... def setUp(self):
@@ -2534,7 +2534,7 @@ behaviour you can switch it off by setting the module level switch
25342534
25352535Alternatively you can just use ``vars(my_mock) `` (instance members) and
25362536``dir(type(my_mock)) `` (type members) to bypass the filtering irrespective of
2537- :const: `mock. FILTER_DIR `.
2537+ :const: `FILTER_DIR `.
25382538
25392539
25402540mock_open
@@ -2549,7 +2549,7 @@ mock_open
25492549 default) then a :class: `MagicMock ` will be created for you, with the API limited
25502550 to methods or attributes available on standard file handles.
25512551
2552- *read_data * is a string for the :meth: `~io.IOBase .read `,
2552+ *read_data * is a string for the :meth: `~io.RawIOBase .read `,
25532553 :meth: `~io.IOBase.readline `, and :meth: `~io.IOBase.readlines ` methods
25542554 of the file handle to return. Calls to those methods will take data from
25552555 *read_data * until it is depleted. The mock of these methods is pretty
@@ -2561,7 +2561,7 @@ mock_open
25612561
25622562 .. versionchanged :: 3.4
25632563 Added :meth: `~io.IOBase.readline ` and :meth: `~io.IOBase.readlines ` support.
2564- The mock of :meth: `~io.IOBase .read ` changed to consume *read_data * rather
2564+ The mock of :meth: `~io.RawIOBase .read ` changed to consume *read_data * rather
25652565 than returning it on each call.
25662566
25672567 .. versionchanged :: 3.5
@@ -2613,7 +2613,7 @@ And for reading files::
26132613Autospeccing
26142614~~~~~~~~~~~~
26152615
2616- Autospeccing is based on the existing :attr: `spec ` feature of mock. It limits the
2616+ Autospeccing is based on the existing :attr: `! spec ` feature of mock. It limits the
26172617api of mocks to the api of an original object (the spec), but it is recursive
26182618(implemented lazily) so that attributes of mocks only have the same api as
26192619the attributes of the spec. In addition mocked functions / methods have the
@@ -2638,8 +2638,8 @@ unit tests. Testing everything in isolation is all fine and dandy, but if you
26382638don't test how your units are "wired together" there is still lots of room
26392639for bugs that tests might have caught.
26402640
2641- :mod: `mock ` already provides a feature to help with this, called speccing. If you
2642- use a class or instance as the :attr: `spec ` for a mock then you can only access
2641+ :mod: `unittest. mock ` already provides a feature to help with this, called speccing. If you
2642+ use a class or instance as the :attr: `! spec ` for a mock then you can only access
26432643attributes on the mock that exist on the real class:
26442644
26452645 >>> from urllib import request
@@ -2677,7 +2677,7 @@ Here's an example of it in use::
26772677 >>> mock_request.Request
26782678 <MagicMock name='request.Request' spec='Request' id='...'>
26792679
2680- You can see that :class: `request.Request ` has a spec. :class: `request.Request ` takes two
2680+ You can see that :class: `! request.Request ` has a spec. :class: `! request.Request ` takes two
26812681arguments in the constructor (one of which is *self *). Here's what happens if
26822682we try to call it incorrectly::
26832683
@@ -2693,8 +2693,8 @@ specced mocks)::
26932693 >>> req
26942694 <NonCallableMagicMock name='request.Request()' spec='Request' id='...'>
26952695
2696- :class: `Request ` objects are not callable, so the return value of instantiating our
2697- mocked out :class: `request.Request ` is a non-callable mock. With the spec in place
2696+ :class: `! Request ` objects are not callable, so the return value of instantiating our
2697+ mocked out :class: `! request.Request ` is a non-callable mock. With the spec in place
26982698any typos in our asserts will raise the correct error::
26992699
27002700 >>> req.add_header('spam', 'eggs')
@@ -2846,8 +2846,8 @@ Sealing mocks
28462846 .. versionadded :: 3.7
28472847
28482848
2849- Order of precedence of :attr: `side_effect `, :attr: `return_value ` and *wraps *
2850- ----------------------------------------------------------------------------
2849+ Order of precedence of :attr: `! side_effect `, :attr: `! return_value ` and *wraps *
2850+ ------------------------------------------------------------------------------
28512851
28522852The order of their precedence is:
28532853
0 commit comments