Using Pytest
Explore how to use Pytest to effectively test Flask APIs, including writing assertions, running tests in a virtual environment, and handling expected exceptions to ensure your code behaves as intended.
We'll cover the following...
We'll cover the following...
Getting started
Pytest is an excellent alternative to the built-in unittest library. It automatically finds our tests and runs them. It makes it easy to do the setup for the tests and break them down afterward, which is important since we have to make it work with Flask applications.
To get started, install pytest using pipenv.
$ pipenv install --dev pytest
Note: It’s already installed here.
Within the pipenv shell, we can test whether or not the installation worked by running pytest --help ...