File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 4646def _is_async_obj (obj ):
4747 if _is_instance_mock (obj ) and not isinstance (obj , AsyncMock ):
4848 return False
49+ if hasattr (obj , '__func__' ):
50+ obj = getattr (obj , '__func__' )
4951 return asyncio .iscoroutinefunction (obj ) or inspect .isawaitable (obj )
5052
5153
Original file line number Diff line number Diff line change @@ -19,6 +19,15 @@ async def async_method(self):
1919 def normal_method (self ):
2020 pass
2121
22+ @classmethod
23+ async def async_class_method (cls ):
24+ pass
25+
26+ @staticmethod
27+ async def async_static_method ():
28+ pass
29+
30+
2231class AwaitableClass :
2332 def __await__ (self ):
2433 yield
@@ -71,6 +80,20 @@ def test_async(mock_method):
7180
7281 test_async ()
7382
83+ def test_is_AsyncMock_patch_staticmethod (self ):
84+ @patch .object (AsyncClass , 'async_static_method' )
85+ def test_async (mock_method ):
86+ self .assertIsInstance (mock_method , AsyncMock )
87+
88+ test_async ()
89+
90+ def test_is_AsyncMock_patch_classmethod (self ):
91+ @patch .object (AsyncClass , 'async_class_method' )
92+ def test_async (mock_method ):
93+ self .assertIsInstance (mock_method , AsyncMock )
94+
95+ test_async ()
96+
7497 def test_async_def_patch (self ):
7598 @patch (f"{ __name__ } .async_func" , return_value = 1 )
7699 @patch (f"{ __name__ } .async_func_args" , return_value = 2 )
Original file line number Diff line number Diff line change 1+ Allow AsyncMock to correctly patch static/class methods
You can’t perform that action at this time.
0 commit comments