@@ -114,20 +114,20 @@ The resulting mock object has the following properties:
114
114
115
115
The mock object also has the following methods:
116
116
117
- * ` reset_mock() ` : reset the mock object to a clean state. This is useful for when
118
- you want to reuse a mock object.
117
+ * ` reset_mock() ` : reset the mock object to a clean state. This is useful for
118
+ when you want to reuse a mock object.
119
119
* ` assert_called() ` : assert that the mock object was called at least once.
120
120
* ` assert_called_once() ` : assert that the mock object was called once.
121
121
* ` assert_called_with(*args, **kwargs) ` : assert that the mock object was last
122
- called in a particular way .
122
+ called with the specified arguments .
123
123
* ` assert_called_once_with(*args, **kwargs) ` : assert that the mock object was
124
124
called once with the given arguments.
125
125
* ` assert_any_call(*args, **kwargs) ` : assert that the mock object was called at
126
126
least once with the given arguments.
127
127
* ` assert_has_calls(calls, any_order=False) ` : assert the mock has been called
128
- with the specified ` calls ` . If any_order is ` False ` then the calls must be
129
- sequential. If any_order is `False` ` then the calls can be in any order, but
130
- they must all appear in mock_calls .
128
+ with the specified ` calls ` . If ` any_order ` is ` False ` then the calls must be
129
+ sequential. If ` any_order ` is ` True ` then the calls can be in any order, but
130
+ they must all appear in ` call_args_list ` .
131
131
* ` assert_never_called() ` : assert that the mock object was never called.
132
132
133
133
As a result, given a mock object it is possible to call it, have it behave in
@@ -145,6 +145,57 @@ assert meaning_of_life == 42, "Meaning of life is not H2G2 compliant."
145
145
m.assert_called_once()
146
146
```
147
147
148
+ ### Asynchronous Mocking
149
+
150
+ As with the ` Mock ` class, the ` AsyncMock ` class provided by uMock allows you to
151
+ create and observe mock objects that, rather than being called, can be
152
+ ` await ` -ed in Python (for when you're writing asynchronous code).
153
+
154
+ This class works in almost exactly the same way as the regular ` Mock ` class,
155
+ but instead of calling it, you ` await ` it. Furthermore, the properties and
156
+ methods on the ` AsyncMock ` class are named differently to reflect the
157
+ ` await ` -able nature of the object.
158
+
159
+ An ` AsyncMock ` object has the following properties:
160
+
161
+ * ` await_count ` : the number of times the mock object has been awaited.
162
+ * ` awaited ` : ` True ` if the mock object was awaited at least once.
163
+ * ` await_args ` : the arguments of the last await on the mock object.
164
+ * ` await_args_list ` : a list of the arguments of each await on the mock object.
165
+
166
+ An asynchronous mock object also has the following methods:
167
+
168
+ * ` reset_mock() ` : reset the mock object to a clean state. This is useful for
169
+ when you want to reuse a mock object.
170
+ * ` assert_awaited() ` : assert that the mock object was awaited at least once.
171
+ * ` assert_awaited_once() ` : assert that the mock object was awaited once.
172
+ * ` assert_awaited_with(*args, **kwargs) ` : assert that the mock object was last
173
+ awaited with the specified arguments.
174
+ * ` assert_awaited_once_with(*args, **kwargs) ` : assert that the mock object was
175
+ awaited once with the given arguments.
176
+ * ` assert_any_await(*args, **kwargs) ` : assert that the mock object was awaited
177
+ at least once with the given arguments.
178
+ * ` assert_has_awaits(awaits, any_order=False) ` : assert the mock has been
179
+ awaited with the specified awaits. If ` any_order ` is ` False ` then the awaits
180
+ must be sequential. If ` any_order ` is ` True ` then the awaits can be in any
181
+ order, but they must all appear in ` await_args_list ` .
182
+ * ` assert_not_awaited() ` : assert that the mock object was never awaited.
183
+
184
+ An ` AsyncMock ` object can be awaited, respond in a specified manner, and you
185
+ can interrogate it about how it has been used:
186
+
187
+ ``` python
188
+ from umock import AsyncMock
189
+
190
+
191
+ m = AsyncMock(return_value = 42 )
192
+
193
+ meaning_of_life = await m()
194
+
195
+ assert meaning_of_life == 42 , " Meaning of life is not H2G2 compliant."
196
+ m.assert_awaited_once()
197
+ ```
198
+
148
199
### Patching
149
200
150
201
The ` patch ` class acts as a function decorator or a context manager. Inside the
0 commit comments