Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7fc972a

Browse files
committed
#17109: fix headings in mock example doc.
1 parent fb13438 commit 7fc972a

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

Doc/library/unittest.mock-examples.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,14 @@ decorator indvidually to every method whose name starts with "test".
418418
.. _further-examples:
419419

420420
Further Examples
421-
================
421+
----------------
422422

423423

424424
Here are some more examples for some slightly more advanced scenarios.
425425

426426

427427
Mocking chained calls
428-
---------------------
428+
~~~~~~~~~~~~~~~~~~~~~
429429

430430
Mocking chained calls is actually straightforward with mock once you
431431
understand the :attr:`~Mock.return_value` attribute. When a mock is called for
@@ -496,7 +496,7 @@ this list of calls for us:
496496

497497

498498
Partial mocking
499-
---------------
499+
~~~~~~~~~~~~~~~
500500

501501
In some tests I wanted to mock out a call to `datetime.date.today()
502502
<http://docs.python.org/library/datetime.html#datetime.date.today>`_ to return
@@ -540,7 +540,7 @@ is discussed in `this blog entry
540540

541541

542542
Mocking a Generator Method
543-
--------------------------
543+
~~~~~~~~~~~~~~~~~~~~~~~~~~
544544

545545
A Python generator is a function or method that uses the `yield statement
546546
<http://docs.python.org/reference/simple_stmts.html#the-yield-statement>`_ to
@@ -582,7 +582,7 @@ To configure the values returned from the iteration (implicit in the call to
582582
583583
584584
Applying the same patch to every test method
585-
--------------------------------------------
585+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
586586

587587
If you want several patches in place for multiple test methods the obvious way
588588
is to apply the patch decorators to every method. This can feel like unnecessary
@@ -642,7 +642,7 @@ exception is raised in the setUp then tearDown is not called.
642642

643643

644644
Mocking Unbound Methods
645-
-----------------------
645+
~~~~~~~~~~~~~~~~~~~~~~~
646646

647647
Whilst writing tests today I needed to patch an *unbound method* (patching the
648648
method on the class rather than on the instance). I needed self to be passed
@@ -681,7 +681,7 @@ with a Mock instance instead, and isn't called with `self`.
681681

682682

683683
Checking multiple calls with mock
684-
---------------------------------
684+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
685685

686686
mock has a nice API for making assertions about how your mock objects are used.
687687

@@ -723,7 +723,7 @@ looks remarkably similar to the repr of the `call_args_list`:
723723

724724

725725
Coping with mutable arguments
726-
-----------------------------
726+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727727

728728
Another situation is rare, but can bite you, is when your mock is called with
729729
mutable arguments. `call_args` and `call_args_list` store *references* to the
@@ -839,7 +839,7 @@ children of a `CopyingMock` will also have the type `CopyingMock`.
839839

840840

841841
Nesting Patches
842-
---------------
842+
~~~~~~~~~~~~~~~
843843

844844
Using patch as a context manager is nice, but if you do multiple patches you
845845
can end up with nested with statements indenting further and further to the
@@ -887,7 +887,7 @@ for us:
887887

888888

889889
Mocking a dictionary with MagicMock
890-
-----------------------------------
890+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
891891

892892
You may want to mock a dictionary, or other container object, recording all
893893
access to it whilst having it still behave like a dictionary.
@@ -962,7 +962,7 @@ mock methods and attributes:
962962

963963

964964
Mock subclasses and their attributes
965-
------------------------------------
965+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
966966

967967
There are various reasons why you might want to subclass `Mock`. One reason
968968
might be to add helper methods. Here's a silly example:
@@ -1025,7 +1025,7 @@ onto the mock constructor:
10251025
10261026
10271027
Mocking imports with patch.dict
1028-
-------------------------------
1028+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10291029

10301030
One situation where mocking can be hard is where you have a local import inside
10311031
a function. These are harder to mock because they aren't using an object from
@@ -1088,7 +1088,7 @@ With slightly more work you can also mock package imports:
10881088

10891089

10901090
Tracking order of calls and less verbose call assertions
1091-
--------------------------------------------------------
1091+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10921092

10931093
The :class:`Mock` class allows you to track the *order* of method calls on
10941094
your mock objects through the :attr:`~Mock.method_calls` attribute. This
@@ -1168,7 +1168,7 @@ order. In this case you can pass `any_order=True` to `assert_has_calls`:
11681168

11691169

11701170
More complex argument matching
1171-
------------------------------
1171+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11721172

11731173
Using the same basic concept as :data:`ANY` we can implement matchers to do more
11741174
complex assertions on objects used as arguments to mocks.

0 commit comments

Comments
 (0)