title: Application context errors when locally testing a (Python) Google Cloud Function
body: <p>I am trying to locally test a Python function that I hope to deploy as a Google Cloud Function. These functions seem to be essentially Flask based, and I have found that the best way to return JSON is to use Flask's jsonify function. This seems to work fine when deployed, but I want to set up some local unit tests, and here is where I got stuck. Simply adding the line to import jsonify, results in the following error:</p>
  
  <pre><code>RuntimeError: Working outside of application context.
  </code></pre>
  
  <p>There are several posts here on Stackoverflow that seem relevant to this issue, and yet Google Cloud Functions do not really follow the Flask pattern. There is no app context, as far as I can tell, and there are no decorators. All of the examples I've found have not been useful to this particular use case. Can anyone suggest a method for constructing a unit test that will respect the application context and still jibe with the GCF pattern here.</p>
  
  <p>I have a unittest, which I can share, but you will see the same error when you run the following, with the method invocation inside of <strong>main</strong>.</p>
  
  <pre><code>import os
  import json
  from flask import jsonify
  from unittest.mock import Mock
  
  def dummy_request(request):
  
      request_json = request.get_json()
      if request_json and 'document' in request_json:
          document = request_json['document']
      else:
          raise ValueError("JSON is invalid, or missing a 'docuemnt' property")
  
      data = document
      return jsonify(data)
  
  
  if __name__ == '__main__':
      data = {"document":"This is a test document"}
      request = Mock(get_json=Mock(return_value=data), args=data)
      result = dummy_request(request)
      print(result)
  </code></pre>