Book Image

Flask Framework Cookbook

By : Shalabh Aggarwal
Book Image

Flask Framework Cookbook

By: Shalabh Aggarwal

Overview of this book

Table of Contents (19 chapters)
Flask Framework Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Determining test coverage


In the previous recipes, test writing was covered, but there is an important aspect to testing called coverage. Coverage determines how much of our code has been covered by the tests. The higher the percentage of coverage, the better our tests (although it's not the only criterion for good tests). In this recipe, we will check the code coverage of our application.

Tip

Remember that 100 percent test coverage does not mean that the code is flawless. However, in any case, it is better than having no tests or lower coverage. Anything that is not tested is broken.

Getting ready

We will use a library called coverage for this recipe. The following is the installation command:

$ pip install coverage

How to do it…

The simplest way of getting the coverage details is to use the command line. Simply run the following command:

$ coverage run –source=../<Folder name of application> --omit=app_tests.py,run.py app_tests.py

Here, --source indicates the directories that are to be...