Allure integration with pytest

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

  1. Install allure-pytest python package with command pip install allure-pytest
  2. 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
  3. Open your terminal and run
    allure --version

    If you see the allure version printed then your setup is successful!!

Generating Allure report using pytest

  1. 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.

  2. 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.

  3. 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
    allure-report


Let me know in the comments if this blog helped you to integrate your tests with Allure!!

15 thoughts on “Allure integration with pytest

  1. How can you share the allure report with other? i can generate it but there is no index.html file in the allure folder

    1. 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/.

  2. 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.

  3. 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.

    1. 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.

  4. 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

    1. Can you please confirm the directory structure.
      Is sub_project_01 a child of main_project or a sibling?
      The volumes docker compose directive needs to be amended based on your folder structure.

    1. Hi Diwakar,
      You can add ENVIRONMENT in your Allure report by adding a environment.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

Leave a Reply

Your email address will not be published. Required fields are marked *