@@ -342,24 +342,25 @@ def wrap_assert_methods(config):
342
342
patcher .start ()
343
343
_mock_module_patches .append (patcher )
344
344
345
- async_wrappers = {
346
- "assert_awaited" : wrap_assert_awaited ,
347
- "assert_awaited_once" : wrap_assert_awaited_once ,
348
- "assert_awaited_with" : wrap_assert_awaited_with ,
349
- "assert_awaited_once_with" : wrap_assert_awaited_once_with ,
350
- "assert_any_await" : wrap_assert_any_await ,
351
- "assert_has_awaits" : wrap_assert_has_awaits ,
352
- "assert_not_awaited" : wrap_assert_not_awaited ,
353
- }
354
- for method , wrapper in async_wrappers .items ():
355
- try :
356
- original = getattr (mock_module .AsyncMock , method )
357
- except AttributeError : # pragma: no cover
358
- continue
359
- _mock_module_originals [method ] = original
360
- patcher = mock_module .patch .object (mock_module .AsyncMock , method , wrapper )
361
- patcher .start ()
362
- _mock_module_patches .append (patcher )
345
+ if hasattr (mock_module , "AsyncMock" ):
346
+ async_wrappers = {
347
+ "assert_awaited" : wrap_assert_awaited ,
348
+ "assert_awaited_once" : wrap_assert_awaited_once ,
349
+ "assert_awaited_with" : wrap_assert_awaited_with ,
350
+ "assert_awaited_once_with" : wrap_assert_awaited_once_with ,
351
+ "assert_any_await" : wrap_assert_any_await ,
352
+ "assert_has_awaits" : wrap_assert_has_awaits ,
353
+ "assert_not_awaited" : wrap_assert_not_awaited ,
354
+ }
355
+ for method , wrapper in async_wrappers .items ():
356
+ try :
357
+ original = getattr (mock_module .AsyncMock , method )
358
+ except AttributeError : # pragma: no cover
359
+ continue
360
+ _mock_module_originals [method ] = original
361
+ patcher = mock_module .patch .object (mock_module .AsyncMock , method , wrapper )
362
+ patcher .start ()
363
+ _mock_module_patches .append (patcher )
363
364
364
365
if hasattr (config , "add_cleanup" ):
365
366
add_cleanup = config .add_cleanup
0 commit comments