title: Testing code that requires a Flask app or request context
body: <p>I am getting <code>working outside of request context</code> when trying to access <code>session</code> in a test.  How can I set up a context when I'm testing something that requires one?</p>
  
  <pre><code>import unittest
  from flask import Flask, session
  
  app = Flask(__name__)
  
  @app.route('/')
  def hello_world():
      t = Test()
      hello = t.hello()
      return hello
  
  class Test:
      def hello(self):
          session['h'] = 'hello'
          return session['h']
  
  class MyUnitTest(unittest.TestCase):
      def test_unit(self):
          t = tests.Test()
          t.hello()
  </code></pre>