【发布时间】:2013-06-26 20:30:42
【问题描述】:
我在测试中尝试访问session 时收到working outside of request context。当我测试需要上下文的东西时,如何设置上下文?
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()
【问题讨论】: