Is there a way to mock flask request object inside a function?
You can use your global request object outside of the process_data method, and pass its attributes to your method:
class ApiDetail(): base_url = request.base_url view_args = request.view_args def process_data(self, process_input, base_url, view_args): try: request_simple_url = self.handle_url(base_url, view_args) return self.validate_input(request_simple_url, process_input) except NotFoundException as e: return {"error": str(e)}, HTTPStatus.UNAUTHORIZED #implementation detail @staticmethod def handle_url(request_base_url, request_arguments): #implementation detaildef test_process_data(): with mock.patch('ApiDetail.validate_input', return_value = NotFoundException): with mock.patch('ApiDetail.handle_url', return_value='test_handled'): assert ApiDetail.process_data(self=ApiDetail, process_input='test_input', base_url='test_url', view_args='test_args') == NotFoundException