From 133b93d337bc0a74da6185062ff696616c92a4f7 Mon Sep 17 00:00:00 2001 From: Kassandra Keeton Date: Thu, 16 Feb 2023 10:11:11 -0600 Subject: [PATCH] update to create_app - if using environment ariables for SECRET_KEY testing is broken when it is outside like originally suggested --- examples/tutorial/flaskr/__init__.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/tutorial/flaskr/__init__.py b/examples/tutorial/flaskr/__init__.py index bb9cce5a..70758db1 100644 --- a/examples/tutorial/flaskr/__init__.py +++ b/examples/tutorial/flaskr/__init__.py @@ -6,16 +6,19 @@ from flask import Flask def create_app(test_config=None): """Create and configure an instance of the Flask application.""" app = Flask(__name__, instance_relative_config=True) - app.config.from_mapping( - # a default secret that should be overridden by instance config - SECRET_KEY="dev", - # store the database in the instance folder - DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"), - ) if test_config is None: # load the instance config, if it exists, when not testing - app.config.from_pyfile("config.py", silent=True) + if os.path.isfile("config.py"): + app.config.from_pyfile("config.py", silent=True) + else: + app.config.from_mapping( + # a default secret that should be overridden by instance config + SECRET_KEY="dev", + # store the database in the instance folder + DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"), + ) + else: # load the test config if passed in app.config.update(test_config)