@@ -506,10 +506,9 @@ def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False,
506
506
507
507
_spec_class = None
508
508
_spec_signature = None
509
- _spec_obj = None
509
+ _spec_asyncs = []
510
510
511
511
if spec is not None and not _is_list (spec ):
512
- _spec_obj = spec
513
512
if isinstance (spec , type ):
514
513
_spec_class = spec
515
514
else :
@@ -518,14 +517,20 @@ def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False,
518
517
_spec_as_instance , _eat_self )
519
518
_spec_signature = res and res [1 ]
520
519
521
- spec = dir (spec )
520
+ spec_list = dir (spec )
521
+
522
+ for attr in spec_list :
523
+ if iscoroutinefunction (getattr (spec , attr , None )):
524
+ _spec_asyncs .append (attr )
525
+
526
+ spec = spec_list
522
527
523
528
__dict__ = self .__dict__
524
529
__dict__ ['_spec_class' ] = _spec_class
525
- __dict__ ['_spec_obj' ] = _spec_obj
526
530
__dict__ ['_spec_set' ] = spec_set
527
531
__dict__ ['_spec_signature' ] = _spec_signature
528
532
__dict__ ['_mock_methods' ] = spec
533
+ __dict__ ['_spec_asyncs' ] = _spec_asyncs
529
534
530
535
def __get_return_value (self ):
531
536
ret = self ._mock_return_value
@@ -1015,8 +1020,7 @@ def _get_child_mock(self, /, **kw):
1015
1020
For non-callable mocks the callable variant will be used (rather than
1016
1021
any custom subclass)."""
1017
1022
_new_name = kw .get ("_new_name" )
1018
- _spec_val = getattr (self .__dict__ ["_spec_obj" ], _new_name , None )
1019
- if _spec_val is not None and asyncio .iscoroutinefunction (_spec_val ):
1023
+ if _new_name in self .__dict__ ['_spec_asyncs' ]:
1020
1024
return AsyncMock (** kw )
1021
1025
1022
1026
if self ._mock_sealed :
0 commit comments