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:
pytestThe 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.inifile. - Run all the methods whose name starts with the
test_prefix in theDroneCategoryTestsclass and display the results. We declared this class in thetests.pyfile and it matches the pattern specified for thepython_filessetting in thepytest.inifile. - 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...