question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mocker.resetall() doesn't work anymore when using mocker.spy()

See original GitHub issue

Using 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
nicoddemuscommented, May 6, 2021

3.6.1 is out. 🎉

0reactions
nicoddemuscommented, May 5, 2021

I would appreciate that, thanks! Been short on time lately.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found