File tree 3 files changed +26
-0
lines changed 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 48
48
def _is_async_obj (obj ):
49
49
if _is_instance_mock (obj ) and not isinstance (obj , AsyncMock ):
50
50
return False
51
+ if hasattr (obj , '__func__' ):
52
+ obj = getattr (obj , '__func__' )
51
53
return asyncio .iscoroutinefunction (obj ) or inspect .isawaitable (obj )
52
54
53
55
Original file line number Diff line number Diff line change @@ -19,6 +19,15 @@ async def async_method(self):
19
19
def normal_method (self ):
20
20
pass
21
21
22
+ @classmethod
23
+ async def async_class_method (cls ):
24
+ pass
25
+
26
+ @staticmethod
27
+ async def async_static_method ():
28
+ pass
29
+
30
+
22
31
class AwaitableClass :
23
32
def __await__ (self ):
24
33
yield
@@ -71,6 +80,20 @@ def test_async(mock_method):
71
80
72
81
test_async ()
73
82
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
+
74
97
def test_async_def_patch (self ):
75
98
@patch (f"{ __name__ } .async_func" , return_value = 1 )
76
99
@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