File tree 3 files changed +24
-1
lines changed
3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change
1
+ 3.6.1 (UNRELEASED)
2
+ ------------------
3
+
4
+ * Fix ``mocker.resetall() `` when using ``mocker.spy() `` (`#237 `_). Thanks `@blaxter `_ for the report and `@shadycuz `_ for the PR.
5
+
6
+ .. _@blaxter : https://github.com/blaxter
7
+ .. _@shadycuz : https://github.com/shadycuz
8
+ .. _#237 : https://github.com/pytest-dev/pytest-mock/issues/237
9
+
1
10
3.6.0 (2021-04-24)
2
11
------------------
3
12
Original file line number Diff line number Diff line change 16
16
from typing import Optional
17
17
from typing import overload
18
18
from typing import Tuple
19
+ from typing import Type
19
20
from typing import TypeVar
20
21
from typing import Union
21
22
@@ -69,8 +70,18 @@ def resetall(
69
70
:param bool return_value: Reset the return_value of mocks.
70
71
:param bool side_effect: Reset the side_effect of mocks.
71
72
"""
73
+ supports_reset_mock_with_args : Tuple [Type [Any ], ...]
74
+ if hasattr (self , "AsyncMock" ):
75
+ supports_reset_mock_with_args = (self .Mock , self .AsyncMock )
76
+ else :
77
+ supports_reset_mock_with_args = (self .Mock ,)
78
+
72
79
for m in self ._mocks :
73
- m .reset_mock (return_value = return_value , side_effect = side_effect )
80
+ # See issue #237.
81
+ if isinstance (m , supports_reset_mock_with_args ):
82
+ m .reset_mock (return_value = return_value , side_effect = side_effect )
83
+ else :
84
+ m .reset_mock ()
74
85
75
86
def stopall (self ) -> None :
76
87
"""
Original file line number Diff line number Diff line change @@ -310,6 +310,9 @@ def bar(self, x):
310
310
assert spy .spy_return == 30
311
311
assert spy .spy_exception is None
312
312
313
+ # Testing spy can still be reset (#237).
314
+ mocker .resetall ()
315
+
313
316
with pytest .raises (ValueError ):
314
317
Foo ().bar (0 )
315
318
assert spy .spy_return is None
You can’t perform that action at this time.
0 commit comments