mocker.resetall() doesn't work anymore when using mocker.spy()
See original GitHub issueUsing the same example from the README about .spy()
but adding a mocker.resetall()
$ cat test_foo.py
def test_spy_method(mocker):
class Foo(object):
def bar(self, v):
return v * 2
foo = Foo()
spy = mocker.spy(foo, 'bar')
assert foo.bar(21) == 42
spy.assert_called_once_with(21)
assert spy.spy_return == 42
mocker.resetall()
$ pytest test_foo.py
============================================= test session starts ==============================================
platform linux -- Python 3.8.0, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /home/blaxter
plugins: mock-3.6.0
collected 1 item
test_foo.py F [100%]
=================================================== FAILURES ===================================================
_______________________________________________ test_spy_method ________________________________________________
mocker = <pytest_mock.plugin.MockerFixture object at 0x7f376c49ddc0>
def test_spy_method(mocker):
class Foo(object):
def bar(self, v):
return v * 2
foo = Foo()
spy = mocker.spy(foo, 'bar')
assert foo.bar(21) == 42
spy.assert_called_once_with(21)
assert spy.spy_return == 42
> mocker.resetall()
test_foo.py:13:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pytest_mock.plugin.MockerFixture object at 0x7f376c49ddc0>
def resetall(
self, *, return_value: bool = False, side_effect: bool = False
) -> None:
"""
Call reset_mock() on all patchers started by this fixture.
:param bool return_value: Reset the return_value of mocks.
:param bool side_effect: Reset the side_effect of mocks.
"""
for m in self._mocks:
> m.reset_mock(return_value=return_value, side_effect=side_effect)
E TypeError: reset_mock() got an unexpected keyword argument 'return_value'
.virtualenvs/test/lib/python3.8/site-packages/pytest_mock/plugin.py:73: TypeError
=========================================== short test summary info ============================================
FAILED test_foo.py::test_spy_method - TypeError: reset_mock() got an unexpected keyword argument 'return_value'
============================================== 1 failed in 0.02s ===============================================
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Usage - pytest-mock documentation
mocker.resetall() : calls reset_mock() in all mocked objects up to this point. ... As of version 3.0.0, mocker.spy also works with async def...
Read more >Why isn't my mock.assert_called_once() passing?
For a number of reasons: mocker.patch returns the mock, so the mocked f2 is mock , not mock.f2 . From the code you...
Read more >Why your mock doesn't work - Ned Batchelder
It makes a mock object, assigns it to the name given, and then restores the original value at the end of the with...
Read more >pytest-mock 3.6.1 - PyPI
mocker.resetall(): calls reset_mock() in all mocked objects up to this point. ... traceback entries from mock module does not work with that option...
Read more >Mocks - Sinon.JS
Mocks (and mock expectations) are fake methods (like spies) with pre-programmed behavior (like ... A mock will fail your test if it is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
3.6.1
is out. 🎉I would appreciate that, thanks! Been short on time lately.