I’m trying to use Mock, to simulate a function in python. Here is my code:
resp, content = request(...)
The request() function needs to return two values. Here’s what I tried:
with patch("syncdatetime.py") as sync_mock:
sync_mock.request.return_value = [obj, '']
But when I run the test, I get the error “Mock object is not iterable.” The request function returns an object of type Mock instead of a list. How can I patch the request function so that it returns a list?
Note of disclosure, I’m new to mock so I’m not an expert, however, I have just suffered the same problem and found that setting the
side_effectattribute to a function that returns an array fixes thingsFrom your example code, change:
to
and define