@@ -155,21 +155,29 @@ def bar(self, arg):
155
155
return arg * 2
156
156
157
157
foo = Foo ()
158
- mocker .spy (foo , 'bar' )
158
+ other = Foo ()
159
+ spy = mocker .spy (foo , 'bar' )
159
160
assert foo .bar (arg = 10 ) == 20
161
+ assert other .bar (arg = 10 ) == 20
160
162
foo .bar .assert_called_once_with (arg = 10 )
163
+ spy .assert_called_once_with (arg = 10 )
161
164
162
165
163
166
def test_instance_method_by_class_spy (mocker ):
167
+ from pytest_mock import mock_module
168
+
164
169
class Foo (object ):
165
170
166
171
def bar (self , arg ):
167
172
return arg * 2
168
173
169
- mocker .spy (Foo , 'bar' )
174
+ spy = mocker .spy (Foo , 'bar' )
170
175
foo = Foo ()
176
+ other = Foo ()
171
177
assert foo .bar (arg = 10 ) == 20
172
- foo .bar .assert_called_once_with (foo , arg = 10 )
178
+ assert other .bar (arg = 10 ) == 20
179
+ calls = [mock_module .call (foo , arg = 10 ), mock_module .call (other , arg = 10 )]
180
+ assert spy .call_args_list == calls
173
181
174
182
175
183
def test_class_method_spy (mocker ):
@@ -179,9 +187,10 @@ class Foo(object):
179
187
def bar (cls , arg ):
180
188
return arg * 2
181
189
182
- mocker .spy (Foo , 'bar' )
190
+ spy = mocker .spy (Foo , 'bar' )
183
191
assert Foo .bar (arg = 10 ) == 20
184
192
Foo .bar .assert_called_once_with (arg = 10 )
193
+ spy .assert_called_once_with (arg = 10 )
185
194
186
195
187
196
def test_class_method_with_metaclass_spy (mocker ):
@@ -196,10 +205,10 @@ class Foo(object):
196
205
def bar (cls , arg ):
197
206
return arg * 2
198
207
199
- mocker .spy (Foo , 'bar' )
208
+ spy = mocker .spy (Foo , 'bar' )
200
209
assert Foo .bar (arg = 10 ) == 20
201
210
Foo .bar .assert_called_once_with (arg = 10 )
202
- return Foo , False
211
+ spy . assert_called_once_with ( arg = 10 )
203
212
204
213
205
214
def test_static_method_spy (mocker ):
@@ -209,6 +218,7 @@ class Foo(object):
209
218
def bar (arg ):
210
219
return arg * 2
211
220
212
- mocker .spy (Foo , 'bar' )
221
+ spy = mocker .spy (Foo , 'bar' )
213
222
assert Foo .bar (arg = 10 ) == 20
214
223
Foo .bar .assert_called_once_with (arg = 10 )
224
+ spy .assert_called_once_with (arg = 10 )
0 commit comments