Book Image

Learning Flask Framework

Book Image

Learning Flask Framework

Overview of this book

Table of Contents (17 chapters)
Learning Flask Framework
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Test-friendly configuration


One of the first obstacles faced by writing tests in a team or with a production environment is, How do we make sure that the tests are run without interfering with the production or even the development database. You certainly don't want to be attempting to fix bugs, or trialing new features and then finding that the data it relies upon has changed. Sometimes, a quick test just needs to be run on a local copy of the database without interference from anyone else, with the Flask app knowing how to use that.

One of the features built into Flask is the ability to load a configuration file depending on the environment variables.

app.config.from_envvar('FLASK_APP_BLOG_CONFIG_FILE')

The preceding method call informs your Flask app that the configuration should be loaded in the file specified in the environment variable FLASK_APP_BLOG_CONFIG_FILE. This has to be an absolute path to the file that you would like to load. Therefore, when you run your tests, a file specific...