In this tutorial, we will test DELETE Request in Python.
Prerequisite:
- Python is installed on the machine
- PIP is installed on the machine
- PyCharm or other Python Editor is installed on the machine
If you need help in installing Python, please refer to this tutorial – How to Install Python on Windows 11.
If you need help in installing PyCharms, please refer to this tutorial – How to install PyCharms on Windows 11.
Below is the example of DELETE Request.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-185.png?w=1083)
Installation of Python Requests Module
Step 1 – If you are using PyCharm IDE then you need to install the Request library. Execute the below command using pip.
pip install -U requests
Step 2 – Install Pytest
pip install -U pytest
Step 3 – Create a new project folder and open it in PyCharm.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-171.png?w=334)
Step 4 – Go to the project folder and Create a new file, name it “DeleteRequest.py”.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-186.png?w=289)
Step 5 – Create the test
Import the required packages.
The DELETE method is typically used to request that a resource be removed or deleted.
import requests
ENDPOINT = 'https://reqres.in/api/users/2'
def test_delete_user():
response = requests.delete(ENDPOINT)
assert response.status_code == 204
requests.delete(url) – function sends a DELETE request to the specified URL.
The response object contains information about the response, including the status code and the response content.
The output of the above program is
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-187.png?w=1089)
That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!