Open brandones opened 8 years ago
+1 for self.client
because it works, thanks
While writing tests for my Flask app I came across a similar problem.
Only from debugging I saw that there was no "config" attribute instead I had to go self.app.application.config
Not sure why it's missing, I've usually always done self.app.config
just like in the production code
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.assertFalse(self.app.application.config['SECRET_KEY'] is 'secret_key')
self.assertTrue(self.app.application.config['DEBUG'] is True)
When the test client is named
self.app
, i.e. you have a situation likeThen when
assertRedirects
tries to access the Flask instance atself.app
it instead gets theFlaskClient
instance and crashes as below.I'm pretty surprised this wasn't a problem before 0.6.0 -- you would think that resolving
self.app
elsewhere, e.g. forself.app.get(...)
would also be a problem, but it apparently wasn't. The obvious solution is to not name the test clientself.app
, but rather, say,self.client
.This is mostly a request for documentation -- somewhere it should advise against doing this. It's also, of course, a note to those running into this confusing error in the future. Actual code change is probably not called for here.