Skip to content

Commit 0c35b65

Browse files
authored
Move remarks about context-manager to the Usage page (#383)
Fix #382
1 parent 4118e33 commit 0c35b65

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

docs/remarks.rst

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,3 @@ to improve the flow of the test:
100100
# ...
101101
102102
But this is arguably a little more complex than using ``pytest-mock``.
103-
104-
Usage as context manager
105-
------------------------
106-
107-
Although mocker's API is intentionally the same as ``mock.patch``'s, its use
108-
as context manager and function decorator is **not** supported through the
109-
fixture:
110-
111-
.. code-block:: python
112-
113-
def test_context_manager(mocker):
114-
a = A()
115-
with mocker.patch.object(a, 'doIt', return_value=True, autospec=True): # DO NOT DO THIS
116-
assert a.doIt() == True
117-
118-
The purpose of this plugin is to make the use of context managers and
119-
function decorators for mocking unnecessary, so it will emit a warning when used as such.
120-
121-
If you really intend to mock a context manager, ``mocker.patch.context_manager`` exists
122-
which won't issue the above warning.

docs/usage.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,24 @@ It may receive an optional name that is shown in its ``repr``, useful for debugg
136136
.. seealso::
137137

138138
``async_stub`` method, which actually the same as ``stub`` but makes async stub.
139+
140+
141+
Usage as context manager
142+
------------------------
143+
144+
Although mocker's API is intentionally the same as ``mock.patch``'s, its use
145+
as context manager and function decorator is **not** supported through the
146+
fixture:
147+
148+
.. code-block:: python
149+
150+
def test_context_manager(mocker):
151+
a = A()
152+
with mocker.patch.object(a, 'doIt', return_value=True, autospec=True): # DO NOT DO THIS
153+
assert a.doIt() == True
154+
155+
The purpose of this plugin is to make the use of context managers and
156+
function decorators for mocking unnecessary, so it will emit a warning when used as such.
157+
158+
If you really intend to mock a context manager, ``mocker.patch.context_manager`` exists
159+
which won't issue the above warning.

0 commit comments

Comments
 (0)