Running unit tests with pytest and checking testing coverage

Now, we will use the pytest command to run tests and measure their code coverage. Make sure you run the command in the Terminal or Command Prompt window in which you have activated the virtual environment, and that you are located within its root folder (Tornado01). Run the following command:

    pytest --cov -v  

The test runner will execute all the functions defined in tests.py that start with the test_ prefix, and will display the results. We use the -v option to instruct pytest to print the test function names and statuses in verbose mode. The --cov option turns on test coverage report generation with the use of the pytest-cov plugin.

The following lines show the sample output: ...

Get Hands-On RESTful Python Web Services - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.