86

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()
4

1 に答える 1