While writing tests for my Flask app I came across an issue when trying to set Flask config settings.
Usually, I do it like this:
import unittest
from factory import create_app
class ConfigTests(unittest.TestCase):
def setUp(self):
app = create_app('flask_test.cfg')
app.testing = True
self.app = app.test_client()
def test_app_is_development(self):
self.assertTrue(self.app.application.config['SECRET_KEY'] is 'secret_key')
self.assertTrue(self.app.application.config['DEBUG'] is True)
This resulted in an error
AttributeError: 'FlaskClient' object has no attribute 'config'
Only from debugging I saw that there was no "config" attribute instead I had to go self.app.application.config
to get it to work.
import unittest
from factory import create_app
class ConfigTests(unittest.TestCase):
def setUp(self):
app = create_app('flask_test.cfg')
app.testing = True
self.app = app.test_client()
def test_app_is_development(self):
self.assertTrue(self.app.application.config['SECRET_KEY'] is 'secret_key')
self.assertTrue(self.app.application.config['DEBUG'] is True)
Am I doing something, did Flask change this in an update or is there a better way to do this?
Aucun commentaire:
Enregistrer un commentaire