pytestを使用してFlaskアプリケーションの単体テストを作成しようとしています。私は(私に語っこれをグーグルでFlaskテストクライアントのURLを生成する
RuntimeError: Attempted to generate a URL without the application context being pushed. This has to be executed when application context is available.
:
def create_app():
from flask import Flask
app = Flask(__name__)
app.config.from_object('config')
import os
app.secret_key = os.urandom(24)
from models import db
db.init_app(app)
return app
とテストクラス:私は、アプリの工場持って
class TestViews(object):
@classmethod
def setup_class(cls):
cls.app = create_app()
cls.app.testing = True
cls.client = cls.app.test_client()
@classmethod
def teardown_class(cls):
cls.app_context.pop()
def test_create_user(self):
"""
Tests the creation of a new user.
"""
view = TestViews.client.get(url_for('create_users')).status_code == 200
をしかし、私は私のテストを実行したときに、私は次のエラーを取得します)、テストクライアントを使用すると自動アプリケーションコンテキストを作成する必要があります。私は何が欠けていますか?