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!!

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

Leave a Reply

Your email address will not be published.