Discovering and running unit tests with pytest
Now, go to the restful01
folder that contains the manage.py
file, with the virtual environment activated, and run the following command:
pytest
The pytest
command and the Django REST framework will perform the following actions:
- Create a clean test database name
test_drones
. - Run all the migrations required for the database.
- Discover the tests that have to be executed based on the settings specified in the
pytest.ini
file. - Run all the methods whose name starts with the
test_
prefix in theDroneCategoryTests
class and display the results. We declared this class in thetests.py
file and it matches the pattern specified for thepython_files
setting in thepytest.ini
file. - Drop the test database named
test_drones
.
Note
It is very important to know that the tests won't make changes to the database we have been using when working with our RESTful Web Service. Notice that the test database name is test_drones
and the database name that we have been using with...