烧瓶测试信号不支持错误

Flask-Testing signals not supported error

当 运行 我的测试时,我得到以下回溯。

in get_context_variable
raise RuntimeError("Signals not supported")
RuntimeError: Signals not supported

__init__.py

from flask_testing import TestCase

from app import create_app, db


class BaseTest(TestCase):
    BASE_URL = 'http://localhost:5000/'

    def create_app(self):
        return create_app('testing')

    def setUp(self):
        db.create_all()

    def tearDown(self):
        db.session.remove()
        db.drop_all()

    def test_setup(self):
        response = self.client.get(self.BASE_URL)
        self.assertEqual(response.status_code, 200)

test_routes.py

from . import BaseTest


class TestMain(BaseTest):

    def test_empty_index(self):
        r = self.client.get('/')
        self.assert200(r)
        self.assertEqual(self.get_context_variable('partners'), None)

看来 get_context_variable 函数调用是错误的来源。如果我尝试使用 assert_template_used,我也会收到此错误。很难找到任何解决方案。

Flask 仅提供信号作为可选依赖项。 Flask-Testing 在某些地方需要信号,如果您尝试在没有它们的情况下做某事,则会引发错误。出于某种原因,一些消息比 Flask-Testing 在别处提出的其他消息更加模糊。 (这是初学者贡献拉取请求的好地方。)

您需要在 Flask 中安装 blinker library to enable signal support

$ pip install blinker