I am trying to mock the return value of the following method import gitlab from unittest.mock import patch def get_all_iters(): gl = gitlab.Gitlab(url='test_url', private_token) result = gl.groups.get(1).iterations.list() # trying to mock the result of this method call return result @patch('gitlab.Gitlab') @patch('gitlab.v4.objects.GroupManager') @patch('gitlab.mixins.ListMixin.list') def test_my_code(mockGitlab, mockGroup, mockList): mockList.return_value = ['a', 'b'] result = get_all_iters() print(result) Although I have tried to mock the return value of the method call, it is still returning the mock object instead of what I tried to mock <MagicMock name='Gitlab().groups.get().iterations.list()' id='1688988996464'> Continue reading...