Contribute Media
A thank you to everyone who makes this possible: Read More

Testing Flask Applications with pytest

Description

Testing a Flask application helps ensure that your app will work as expected for your end users. This talk provides an introduction to using pytest for testing Flask applications. Before diving into how to use pytest, this talk explains what should be tested in a Flask application. Next, detailed examples are covered on how to write unit and functional test functions with pytest that are specific to Flask applications. Documentation of the tests is also highlighted using the GIVEN-WHEN-THEN approach. After writing tests, running the tests using pytest (with different options) is presented to demonstrate how easy and powerful pytest is. Examples include verbose mode, running only the last failed tests, and running specific test cases. Next, the concept of fixtures in pytest is presented and detailed examples of how to initialize the state of a Flask application are covered. This section includes properly initializing a Flask application to avoid not having the application context created. Finally, the idea of code coverage is introduced and an example of running coverage.py on a Flask application is demonstrated.

Details

Improve this page