Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask-Testing signals not supported error

When running my tests I am getting the following traceback.

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)

It appears that the get_context_variable function call is where the error is coming from. I also receive this error if I try and use assert_template_used. Having a rather difficult time finding any resolution to this.

like image 239
Adam Avatar asked Jul 20 '16 21:07

Adam


People also ask

How do you test a Flask application?

Flask provides a way to test your application by exposing the Werkzeug test Client and handling the context locals for you. You can then use that with your favourite testing solution.

What are Flask signals?

What are signals? Signals help you decouple applications by sending notifications when actions occur elsewhere in the core framework or another Flask extensions. In short, signals allow certain senders to notify subscribers that something happened.


1 Answers

Flask only provides signals as an optional dependency. Flask-Testing requires signals in some places and raises an error if you try to do something without them. For some reason, some messages are more vague than others Flask-Testing raises elsewhere. (This is a good place for a beginner to contribute a pull request.)

You need to install the blinker library to enable signal support in Flask.

$ pip install blinker
like image 194
davidism Avatar answered Sep 28 '22 07:09

davidism