Introduction
In this article, I will explain how to attach our public IP address to Allure report using Pytest and Requests the work on this project was developed together withElias Shourosh.
The technological stack used to implement the solution is:
Programing language: Python
Testing Framework: pytest
Reporting Framework: Allure
HTTP Library: Requests
Why should we attach our IP address to the report?
- This is done mainly for debugging purposes - if the automation fails, we can filter the logs in a centralized logging system like Amazon CloudWatch.
- The IP also helps to detect a machine while running a parallel run with multiple containers or VMs.
Implementing the Solution
We will write a simple function that will do a GET request and return the IP address from the following AWS service: http://checkip.amazonaws.com
def get_public_ip():
return requests.get("http://checkip.amazonaws.com").text.rstrip()
We will use this method to attach the IP to the allure report in case of test failure:
allure.attach(get_public_ip(), "public ip address", attachment_type=allure.attachment_type.TEXT)
Now each failure will contain our public IP
Happy testing!