File tree Expand file tree Collapse file tree 2 files changed +21
-20
lines changed Expand file tree Collapse file tree 2 files changed +21
-20
lines changed Original file line number Diff line number Diff line change @@ -100,23 +100,3 @@ to improve the flow of the test:
100
100
# ...
101
101
102
102
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.
Original file line number Diff line number Diff line change @@ -136,3 +136,24 @@ It may receive an optional name that is shown in its ``repr``, useful for debugg
136
136
.. seealso ::
137
137
138
138
``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.
You can’t perform that action at this time.
0 commit comments