Mocking class method with pytest-mock returns error

Solution 1:

In your case since you are patching the class that is present within the test file itself you would use mocker.patch.object.

mock_function = mocker.patch.object(RealClass, 'some_function')

collected 1 item                                                               

tests/test_grab.py::test_the_function PASSED                             [100%]

============================== 1 passed in 0.03s ===============================