· 6 years ago · Sep 13, 2019, 02:32 PM
1# app.py
2def create_app(config, extra_test_args):
3 app = flask.Flask(__name__)
4 app.config.from_object(config) # you load the default config
5 if extra_test_args:
6 app.config.update(**extra_test_args) # override further whatever you need
7 return app
8
9# authenticated_tests.py
10from app.py import create_app
11flask_app = create_app('test', {'SECRET_KEY': None})
12
13
14# integration_tests.py
15from app.py import create_app
16flask_app = create_app('production', {'SECRET_KEY': '34294321hfjdsaf', 'DATABASE': 'test.db', 'CREDENTIALS': {'username': 'bogus', 'password': 'boggy'}}) # use all the production settings except for the sensitive ones which you'd override
17
18# see how this is super useful with factories ? without them you'd have to use the same app and alter the settings globally