我正在working outside of request context试图访问时,session在测试。测试需要测试的内容时,如何设置上下文?import unittestfrom flask import Flask, sessionapp = Flask(__name__)@app.route('/')def hello_world(): t = Test() hello = t.hello() return helloclass Test: def hello(self): session['h'] = 'hello' return session['h']class MyUnitTest(unittest.TestCase): def test_unit(self): t = tests.Test() t.hello()
2 回答

哔哔one
TA贡献1854条经验 获得超8个赞
我包装了与Flask无关或与之无关的功能,这些功能需要请求数据才能起作用;)app_app.test_request_context():
并确实起作用
添加回答
举报
0/150
提交
取消