Unable to mock api call inner Function in Flask Unitest Unable to mock api call inner Function in Flask Unitest flask flask

Unable to mock api call inner Function in Flask Unitest


Solved this by creating another mocked function.

class FakedResponse:    """Fake Response2."""    status_code = 200    @staticmethod    def json():        """Json Response."""        return response

then Modifying actual test function by

@mock.patch('src.recommender.RecommendationTask.execute', side_effect=None, return_result=None)def test_recommendation_api_endpoint(_mock_object, client):    """Check the /recommender REST API endpoint."""    r.cursor = FakedResponse()    rec_resp = client.post(api_route_for("recommender"),                           data=json.dumps(payload), content_type='application/json')