title: Working outside of application context; FlaskClient object has no attribute 'app_context'
body: <p>We are getting <code>FlaskClient object has no attribute 'app_context'</code> with this test:</p>
  
  <p>app.py:</p>
  
  <pre><code>import logging
  from logging.handlers import RotatingFileHandler
  
  from blueprints import default, otherstuff
  from global_vars import app, db
  
  
  def generate_app():
      app.config.from_object('config.flask_config')
      db.init_app(app)
  
  
     # registering blueprints
      app.register_blueprint(default.default)
      app.before_request(oauth_package.authenticate_all_requests)
      return app
  
  if __name__ == '__main__':
      flask_app = generate_app()
      flask_app.run(port=5002, debug=True)
  </code></pre>
  
  <p>testfile.py:</p>
  
  <pre><code>import unittest
  import mock
  from starter_file import generate_app
  import flask
  import blueprints
  
  
  class TestBase(unittest.TestCase):
  
      def setUp(self):
          # creates a test client
          app = generate_app()
          app.testing = True
          self.app = app.test_client()
          # propagate the exceptions to the test client
  
      @mock.patch('blueprints.default.get_current_user_role')
      def test_qppage_without_coockie(self,  mocked_get_current_user_role):
          mocked_get_current_user_role.return_value = 'ap'
          with self.app.app_context():
              result = blueprints.default.home()
              print result
              # assert the status code of the response
              self.assertEqual(result.status_code, 302)
  
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  
  <p>and <code>Runtime error: Working outside of application context</code> with this code:</p>
  
  <pre><code>class TestBase(unittest.TestCase):
  
      def setUp(self):
          # creates a test client
          app = generate_app()
          app.testing = True
          self.app = app.test_client()
          # propagate the exceptions to the test client
  
      @mock.patch('blueprints.default.get_current_user_role')
      def test_qppage_without_coockie(self,  mocked_get_current_user_role):
          mocked_get_current_user_role.return_value = 'ap'
          result = blueprints.default.home()
          print result
          # assert the status code of the response
          self.assertEqual(result.status_code, 302)
  </code></pre>