This tutorial series is dedicated to exploring the basics of inbuilt Django testing and introduces Pytest and its various plugins to help us write better code
Currently we cover the following:
Code coverage
,Generating fixtures using Mixer
Complex testing of edge-cases using Hypothesis
Testing Serializers
Testing DRF Views
DRF authentication testing
Github Actions
- Full Course(FREE): https://geoffreynyaga.com/courses/pytest-django-and-django-rest-framework/
- YouTube Playlist: https://www.youtube.com/playlist?list=PLP1DxoSC17LZTTzgfq0Dimkm6eWJQC9ki
mkdir <my_project>
cd my_project
git clone https://github.com/geoffreynyaga/django-and-djangorestframework-pytest-tutorial.git .
The projects uses pytest and black as the formatting option. The tests also check for consistencies on code format.
To initiate tests follow the steps below:
-
Its advised to create a virtual environment in the root folder
virtualenv venv
-
Activate the environent.
a. For Linux/MacOS users use the command below
source venv/bin/activate
b. for windows users
cd venv/Scripts activate.bat
-
Install the requirements
pip install -r requirements.txt
-
Run the pytest command
pytest
The testing results will be displayed and there will also be a htmlcov
folder generated inside the project that will contain the code coverage details.
. ├── accounts │ ├── api │ │ └── tests │ └── migrations ├── classroom ├── htmlcov └── venv
Open up the folder and open the index.html
in your browser to see this information.
.
├── accounts
│ ├── api
│ │ └── tests
│ └── migrations
├── classroom
├── htmlcov
└── venv # after you create the virtualenv