Recently, I was on the lookout for a good open-source reporting tool other than the ReportPortal tool which we already integrated with pytest in the past. As a result, I came across a tool called Allure. When I started integrating allure with pytest, I stumbled upon a couple of errors as there was no straightforward guide to do so. Therefore, I am writing this blog post!!
What is Allure?
Allure framework is a lightweight test reporting tool that shows useful information about test execution in a neat web report form. It can be integrated with popular testing frameworks across languages. To know more about allure you can read through its documentation.
Allure integration with pytest
Creating a test
To illustrate how to integrate Allure with pytest, we will be making use of a simple python test that verifies the Qxf2 website’s title.
""" This script will open the Qxf2 website and verify its title """ from selenium import webdriver site_url = 'https://qxf2.com/' def test_site_title(): "Checks Qxf2's website title" driver = webdriver.Chrome() driver.get(site_url) assert driver.title == 'Qxf2 Services: Outsourced Software QA for startups' |
Allure Setup
- Install allure-pytest python package with command pip install allure-pytest
- Next, download the latest allure package zip file from the allure-framework GitHub repo
- Unzip the downloaded zip file
- Copy the path till bin
- Add it to the path environment variable
- Open your terminal and run
allure --version
If you see the allure version printed then your setup is successful!!
Generating Allure report using pytest
- In your project directory, you first need to generate a folder to save the allure reports, you can automatically generate this with a command
allure generate
This will create a folder named allure-report in your project directory.
- You are now set to run your test with pytest runner by specifying the directory path to save your allure report, for example :
pytest --alluredir=allure-report/
Once test execution completes, all the test results would get stored in allure-report directory.
- You can now view the allure-report in the browser with the command –
allure serve allure-report/
This will open up the report in your default browser automatically and would look like
Let me know in the comments if this blog helped you to integrate your tests with Allure!!
I am a software tester with more than 3 years of experience. I started my career in an e-commerce startup called Browntape Technologies. I was looking forward to work with a software testing organization which would help me showcase my testing and technical skills. So I joined Qxf2. I love scripting in Python and using Selenium. I live in Goa and enjoy its beaches. My hobbies include playing cricket, driving and exploring new places.
How can you share the allure report with other? i can generate it but there is no index.html file in the allure folder
Hi Mojiz,
I guess you could use Allure Docker Service container you can get an e-mailable report. https://github.com/fescobar/allure-docker-service#customize-emailable-report. You can also checkout this tool which can build the whole allure generate’ result folder into a single html file viewable from browser: https://github.com/MihanEntalpo/allure-single-html-file
the best allure guide, thanks!
you forgot to mention allure is a java based tool which means you require a JDK installtion
Hi Steve,
The blog mainly focuses on integrating Allure with Pytest, and we believe this doesn’t require JDK to be installed. However, there are a few adapters that require prior JDK installation. For further details on setting up Allure you can refer to the official documentation https://docs.qameta.io/allure/.
not worked for me i cant see any file which will show me the results .
iam running from windows pycharm i followed the steps but no luck.
Hello, Swapnil,
could you please provide more details about what exactly the problem is so that we can investigate further?
Thanks,
Raghava
Hi All, I am also trying to generate allure report and share the web URL with other team members once the report is generated.
I am running my Github Action pipelines to test using pytest framework for python test. Just to give brief background, we are running self hosted ubuntu ec2 instances for these tests execution. Once the trigger happen it pull the AMI(Pre configured baked) and spin the ec2 instance and checkout the repo and after setting up some steps for requirement.txt and allure setup through pip start executing the test scripts. Now in my github action I want to generate the test results put them in a directory and from there want to create a webURL to generate reoprt dashbaord. Once we get this report, I want to share it with other members or some kind of URL which I can share through email. Also after the spinning of ec2 instances and once the test scripts are done and dashboard created we are stopping the ec2 instance and terminating the instances.. So do we need to save this reports somewhere and retaining them for 30 days.
Hi Gaurav,
One option to host and share your report with others is to use a platform like Netlify, that helps to host static websites. You can use Netlify with your GitHub Actions pipeline and generate a report dashboard. Whenever the test scripts are executed and results generated, trigger the deployment to Netlify. Regarding the retention of reports, you can check for storage solution like Amazon S3 or cloud-based file storage service.
Hey Gaurav … Very nice blog!!
I was wondering if u can help me set up allure server using docker for multiple projects.
I have the following setup:
– allure –version 2.24.0
– Pytest, Behave
– Folder structure:
— main_project
— sub_project_01
— sub_project_02
— sub_project_03
— sub_project_04
— sub_project_05
– Have docker-compose.yml in main_project
– My docker-compose.yml:
version: ‘3’
services:
allure:
image: “frankescobar/allure-docker-service”
restart: always
environment:
CHECK_RESULTS_EVERY_SECONDS: NONE
KEEP_HISTORY: 1
KEEP_HISTORY_LATEST: 35
EMAILABLE_REPORT_TITLE: “Test Automation Run Report”
ports:
– “5151:5151”
volumes:
# – ${PWD}/projects:/app/projects \
– ${PWD}/allure-results:/app/allure-results
– ${PWD}/allure-reports:/app/default-reports
allure-ui:
image: “frankescobar/allure-docker-service-ui”
restart: always
environment:
ALLURE_DOCKER_PUBLIC_API_URL: “http://localhost:5151”
ALLURE_DOCKER_PUBLIC_API_URL_PREFIX: “”
ports:
– “5353:5353”
mailhog:
image: mailhog/mailhog
container_name: ‘mailhog’
ports:
– “1025:1025”
– “8025:8025”
I am able to generate temp report using allure server allure-results for single project but nothing on server and nothing when I use `${PWD}/projects:/app/projects \`
I keep on getting:
This page isn’t workinglocalhost didn’t send any data.
ERR_EMPTY_RESPONSE
Can you please confirm the directory structure.
Is
sub_project_01
a child ofmain_project
or a sibling?The
volumes
docker compose directive needs to be amended based on your folder structure.Hi,
The report is great!
I want to attach other log files, how can we achieve it?
Thanks,
TKB
Please refer doc – https://docs.qameta.io/allure/#_attachments_5
You need to make littlebit modification to your code to attach custom log files.
import allure
# Your test code here
# Attach a log file
allure.attach.file("path/to/your/logfile.log", name="Custom Log File", attachment_type=allure.attachment_type.TEXT)
ENVIRONMENT
There are no environment variables ITS SHOWING EMPTY HOW CAN I ADD IN ENVIRONMENT IN MY ALLURE REPORT
Hi Diwakar,
You can add
ENVIRONMENT
in your Allure report by adding aenvironment.properties
file to your reports directory.You can refer Environment file to find out how to add values to the environment properties file.
We hope this helps display the Environment information. Let us know if this is useful or you need more information.
Thank you