相关疑难解决方法(0)

测试需要Flask应用程序或请求上下文的代码

working outside of request context试图session在测试中访问时得到.当我测试需要的内容时,如何设置上下文?

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()
Run Code Online (Sandbox Code Playgroud)

python flask

48
推荐指数
1
解决办法
4万
查看次数

标签 统计

flask ×1

python ×1