I'm writing tests for my Flask project, and are trying to mock my database model. The code looks something like this:
import unittest.mock
@unittest.mock.patch("server.models.user")
def test_that_response_contain_correct_user_data(self, mocked_user):
This results in this error message:
TypeError: test_that_response_contain_correct_user_data() missing 1 required positional argument: 'mocked_user'
So it looks like the mocking framwork doesn't inject the mocked data into the function. Does anyone know what may be causing this?
test_that_response_contain_correct_user_data()
a function (not belonging to any class) or a method (part of a class)? If it is a function, the first argumentself
gets the patch object, while the second argument is not provided (so the error message). In that case, removeself
. – Oakland@patch.object
, though. – Moor