@@ -18,6 +18,10 @@ async def async_method(self):
1818 def normal_method (self ):
1919 pass
2020
21+ class AwaitableClass :
22+ def __await__ (self ):
23+ yield
24+
2125async def async_func ():
2226 pass
2327
@@ -160,6 +164,10 @@ def test_create_autospec_instance(self):
160164 with self .assertRaises (RuntimeError ):
161165 create_autospec (async_func , instance = True )
162166
167+ def test_create_autospec_awaitable_class (self ):
168+ awaitable_mock = create_autospec (spec = AwaitableClass ())
169+ self .assertIsInstance (create_autospec (awaitable_mock ), AsyncMock )
170+
163171 def test_create_autospec (self ):
164172 spec = create_autospec (async_func_args )
165173 awaitable = spec (1 , 2 , c = 3 )
@@ -321,6 +329,13 @@ def test_is_child_AsyncMock(self):
321329 self .assertIsInstance (mock .normal_method , MagicMock )
322330 self .assertIsInstance (mock , MagicMock )
323331
332+ def test_magicmock_lambda_spec (self ):
333+ mock_obj = MagicMock ()
334+ mock_obj .mock_func = MagicMock (spec = lambda x : x )
335+
336+ with patch .object (mock_obj , "mock_func" ) as cm :
337+ self .assertIsInstance (cm , MagicMock )
338+
324339
325340class AsyncArguments (unittest .TestCase ):
326341 def test_add_return_value (self ):
0 commit comments