We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 25de852 commit 0df91f9Copy full SHA for 0df91f9
tests/test_pytest_mock.py
@@ -243,6 +243,24 @@ def bar(self, arg):
243
assert spy.return_value == 20
244
245
246
+def test_instance_method_spy_exception(mocker):
247
+ excepted_message = "foo"
248
+ class Foo(object):
249
+ def bar(self, arg):
250
+ raise Exception(excepted_message)
251
+
252
+ foo = Foo()
253
+ other = Foo()
254
+ spy = mocker.spy(foo, "bar")
255
256
+ with pytest.raises(Exception) as exc_info:
257
+ foo.bar(10)
258
+ assert str(exc_info.value) == excepted_message
259
260
+ foo.bar.assert_called_once_with(arg=10)
261
+ assert spy.return_value == exc_info.value
262
263
264
@skip_pypy
265
def test_instance_method_by_class_spy(mocker):
266
class Foo(object):
0 commit comments