Book Image

Flask Blueprints

By : Joel Perras
Book Image

Flask Blueprints

By: Joel Perras

Overview of this book

Table of Contents (14 chapters)

Unit and functional testing


One of the primary benefits of implementing an application factory to hand out the Flask application instances is that we have the abilities to test the application more effectively. We can construct different application instances for different test cases and can be sure that they are as isolated from each other as possible (or as much as Flask/Werkzeug will allow).

The mainstay of the testing libraries in the Python ecosystem is unittest, which is included in the standard library and includes much of the functionalities that are expected of an xUnit framework. While a complete exposition on unittest is largely out of the scope of this book, a typical class-based test case will follow this basic skeleton, assuming that we are still using the factory pattern to separate our application configuration from instantiation:

from myapp import create_app
import unittest

class AppTestCase(unittest.TestCase):

    def setUp(self):
        app = create_app()  # Could also...