Skip to content

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

@blaxter

Description

@blaxter

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions