[Python] Allure Report Setup Guide | Visualize pytest × Playwright Results Beautifully

test-automation

When automating tests with pytest, you’ll often want to share results as something more readable than a plain HTML table. With Allure Report, you can output pytest results as rich HTML reports complete with graphs, screenshots, and step-by-step details. This article covers everything from setting up Allure in a Python × pytest environment to generating screenshot-attached reports and integrating with GitHub Actions.

Adding Allure Report to your pytest setup lets you output beautiful HTML reports with graphs, screenshots, and step-level detail — taking your QA reporting to the next level.

📌 Who This Article Is For

  • QA engineers who want more readable test reports than pytest-html provides
  • Anyone who wants to learn how to set up Allure from scratch
  • Those who want to share Playwright × pytest results with their team or manager
  • Engineers who want richer reports in their CI/CD pipeline

✅ What You’ll Learn

  • How to install Allure in a Python/pytest project and generate reports
  • How to add steps, descriptions, and screenshots to your tests
  • How to auto-generate and publish Allure reports in GitHub Actions

👤 About the Author

Working as a QA engineer using Selenium, Playwright, and pytest for real-world test automation. Allure has been set up in actual projects, and I’ll walk you through the common pitfalls from a practitioner’s perspective. Code is publicly available on GitHub: github.com/YOSHITSUGU728/automated-testing-portfolio

📌 3 Things You Can Do with Allure

  • Beautiful HTML reports: A dashboard with graphs, pie charts, and test history at a glance
  • Detailed test visualization: View steps, screenshots, and logs per individual test
  • CI/CD integration: Auto-generate in GitHub Actions and publish to GitHub Pages

pytest-html works fine for basic reporting, but as your test suite grows you’ll start running into these frustrations:

  • Hard to see at a glance which tests failed and why
  • No way to view failure causes with screenshots attached
  • No visibility into test run history or trends

Allure solves all of these problems — it’s the most widely used report framework in the test automation field. This article walks you through everything from installation to report generation and CI/CD integration.

① pytest-html vs Allure: Which Should You Use?

Let’s start by comparing Allure and pytest-html side by side.

Featurepytest-htmlAllure
Setup ease⭐⭐⭐ pip install only⭐⭐ CLI must be installed separately
Report visualsSimple HTML tableGraphs, dashboard, history included
Step details❌ Not supported✅ Add with @allure.step
Screenshot attachment🔺 Limited✅ Easy with allure.attach
History & trends❌ Not supported✅ Compare against past runs
CI/CD integration✅ Artifact storage✅ GitHub Pages publishing possible
💡 When to use which: For small projects under 10–20 tests or local verification, pytest-html is sufficient. Once you need to share results with a team, integrate into CI/CD, or your test count exceeds 50, that’s the right time to consider moving to Allure.

② How to Install Allure for Python × pytest

Allure requires two separate installations: the Python Allure adapter and the Allure CLI for generating HTML reports.

Installing the Python Package

First, install the Allure adapter that integrates with pytest.

# Install allure-pytest
pip install allure-pytest

# Add to requirements.txt
# allure-pytest

Installing the Allure CLI

Next, install the Allure CLI that generates HTML reports. The CLI requires Java to be installed. Installation varies by OS.

# macOS (using Homebrew)
brew install allure

# Windows (using Scoop)
scoop install allure

# Linux (manual install)
# 1. Download the zip from the Allure official site
# 2. Extract and add bin/ to your PATH

# Verify installation
allure --version
💡 Java-free option: In CI environments (GitHub Actions), you can use allure-combine or allurectl to generate reports without Java. For quick local verification, using pytest-html alongside Allure is also a practical approach.

③ How to Generate an Allure Report with pytest

Allure works in two steps: first generate result files during the pytest run, then convert them to an HTML report using the CLI.

STEP 1: Run Tests (Generate Result Files)

Run pytest with the --alluredir option to output Allure result files into the specified folder.

# Output result files to allure-results folder
pytest --alluredir=allure-results

# Run only smoke tests and output results
pytest -m smoke --alluredir=allure-results

# Clear existing result files before running
pytest --alluredir=allure-results --clean-alluredir

STEP 2: Generate and View the HTML Report

Once result files are generated, convert them to an HTML report using the Allure CLI. There are two approaches: one for local viewing and one for CI/CD artifact storage.

# Launch a local server and open in browser (for local viewing)
allure serve allure-results

# Output as HTML files (for CI/CD artifact storage)
allure generate allure-results -o allure-report --clean

Sample Execution Output

$ pytest --alluredir=allure-results -v

========================= test session starts ==========================
collected 3 items

tests/smoke/test_login_smoke.py::test_login_success          PASSED  [ 33%]
tests/smoke/test_login_smoke.py::test_login_wrong_password   PASSED  [ 66%]
tests/smoke/test_login_smoke.py::test_login_locked_out_user  PASSED  [100%]

========================== 3 passed in 5.34s ===========================

$ allure serve allure-results
Starting web server...
Server started at: http://127.0.0.1:PORT/

④ How to Add Allure Info (step & severity) to pytest Tests

Allure’s real power comes from adding decorators to your test code to enrich reports with detailed information.

Basic Decorators

Combine the following decorators to categorize tests by feature, severity, and story in the report.

import allure
import pytest
from pages.login_page import LoginPage

@allure.epic("Authentication")         # Top-level category (product feature)
@allure.feature("Login")               # Mid-level category (feature name)
@allure.story("Successful Login")      # Sub-level category (user story)
@allure.severity(allure.severity_level.CRITICAL)  # Severity level
@pytest.mark.smoke
def test_login_success(page, base_url, valid_credentials):
    """Verify that a valid login succeeds"""

    with allure.step("Navigate to login page"):
        login_page = LoginPage(page)
        login_page.navigate(f"https://{base_url}/")

    with allure.step("Enter credentials and submit"):
        login_page.login(
            valid_credentials["username"],
            valid_credentials["password"]
        )

    with allure.step("Verify URL after login"):
        assert page.url.endswith("/inventory.html"), \
            f"URL after login does not match expected: {page.url}"

Severity Levels

SeverityWhen to use
BLOCKERFailure blocks the release entirely
CRITICALCore feature tests (login, payment, etc.)
NORMALStandard functional tests
MINORMinor feature tests
TRIVIALUI detail checks, copy verification, etc.

⑤ How to Auto-Attach Screenshots with Playwright × Allure

One of the most powerful features of the Playwright × Allure combination is automatic screenshot attachment on failure. Adding this to conftest.py applies it to every test automatically.

Add the following code to tests/conftest.py. It captures a screenshot at the moment a test fails and attaches it to the Allure report.

# Add to tests/conftest.py

import allure
import pytest

@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
    """Attach a screenshot to the Allure report when a test fails"""
    outcome = yield
    report = outcome.get_result()

    # When the test has failed
    if report.when == "call" and report.failed:
        # Only when the test uses the page fixture
        page = item.funcargs.get("page")
        if page:
            screenshot = page.screenshot()
            allure.attach(
                screenshot,
                name="Screenshot on failure",
                attachment_type=allure.attachment_type.PNG
            )

To attach a screenshot manually at any point during a test, use the following approach:

import allure

def test_add_to_cart(logged_in_page):
    page = logged_in_page

    with allure.step("Add item to cart"):
        page.click("[data-test='add-to-cart-sauce-labs-backpack']")

        # Manually attach a screenshot at this point
        allure.attach(
            page.screenshot(),
            name="After adding to cart",
            attachment_type=allure.attachment_type.PNG
        )

    with allure.step("Verify cart badge count"):
        badge = page.locator(".shopping_cart_badge").text_content()
        assert badge == "1"

⑥ pytest.ini Configuration for Allure

Add Allure-specific settings to pytest.ini so you don’t have to type --alluredir manually on every run.

# pytest.ini
[pytest]
testpaths = tests

addopts =
    -v
    --tb=short
    --alluredir=allure-results
    --clean-alluredir

markers =
    smoke: Smoke tests
    regression: Regression tests
    e2e: E2E tests
💡 Note: Adding --clean-alluredir clears old result files before each run, preventing results from previous runs from mixing in. However, if you want to preserve history trends, omit this option and manage history manually — or use CI/CD artifact features to carry it over.

⑦ How to Auto-Generate Allure Reports in GitHub Actions

Here’s the configuration for auto-generating Allure reports in GitHub Actions and saving them as artifacts. Copy and use this YAML file directly.

# .github/workflows/allure.yml

name: E2E Tests with Allure Report

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python 3.11
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt

      - name: Install Playwright browsers
        run: playwright install chromium --with-deps

      - name: Run tests (output Allure result files)
        run: pytest --alluredir=allure-results
        continue-on-error: true   # continue even if tests fail

      - name: Set up Allure CLI
        uses: simple-elf/allure-setup-action@master
        with:
          allure_version: "2.27.0"

      - name: Generate Allure HTML report
        run: allure generate allure-results -o allure-report --clean

      - name: Upload report as artifact
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: allure-report
          path: allure-report/
          retention-days: 30
💡 Pro Tip: Adding continue-on-error: true to the test step ensures that even when tests fail, the subsequent allure generate step still runs. Since reports are most needed precisely when tests fail, always include this setting.

FAQ

Q. What’s the difference between allure serve and allure generate?

allure serve starts a local server and automatically opens the report in your browser. It doesn’t save files, making it ideal for quick local checks. allure generate outputs HTML files to disk — use this for CI/CD artifact storage or deploying to GitHub Pages.

Q. Can I use pytest-html and Allure at the same time?

Yes. Add both --alluredir=allure-results and --html=reports/report.html --self-contained-html to addopts in pytest.ini and both reports will be generated simultaneously. This is useful during a transition period — rolling out Allure to the team while keeping pytest-html available for quick checks.

Q. Do I have to use @allure.step?

No, it’s not required. Reports are generated even without @allure.step. That said, adding steps causes each operation to appear in a nested hierarchy in the report, making it immediately clear which step failed. It’s especially recommended for complex E2E tests or reports shared with a team.

Q. How do I show test history and trend graphs?

Copy the allure-report/history folder from the previous run into allure-results/history before running allure generate, and the history graph will appear. In CI/CD, the standard approach is to download the previous report from artifacts and carry the history folder forward.

⚠️ 7 Common Pitfalls When Setting Up Allure Report

Allure has more moving parts than simpler tools, which means more places to get stuck. Knowing these pitfalls in advance will save you a lot of unnecessary debugging.

① Installing allure-pytest doesn’t give you the allure command

pip install allure-pytest only installs the Python adapter (which generates result files). The allure command for generating HTML reports requires a separate Allure CLI installation. pip alone won’t give you the command.

② allure generate succeeds even when allure-results is empty

If pytest fails to collect any tests (collected 0 items etc.), the allure-results folder may be created but contain no files. allure generate will still succeed, but the resulting report will be an empty dashboard. Always verify that pytest is actually running tests before investigating the report.

③ allure serve exits without opening a browser

In WSL (Windows Subsystem for Linux) or SSH-connected environments, allure serve may fail to launch a browser automatically and exit with an error. In that case, use allure generate allure-results -o allure-report to generate HTML files and open allure-report/index.html directly in your browser.

④ Double-clicking index.html shows a blank page

Opening Allure report files by double-clicking causes browser security restrictions to block JavaScript, resulting in a blank page. Always open the report via allure serve or a local server (e.g. python -m http.server).

⑤ allure command not found in GitHub Actions

CI environments don’t have Allure CLI pre-installed. You need to install it within the workflow using an action like simple-elf/allure-setup-action. Just pip install allure-pytest alone is not enough to use the allure generate command.

⑥ Forgetting continue-on-error means no report is generated when tests fail

GitHub Actions jobs stop by default the moment a test fails. Without continue-on-error: true on the pytest step, the allure generate step never runs and no report is produced. Reports are most critical when tests fail, so this setting is essential.

⑦ Using –clean-alluredir wipes out your history trends

--clean-alluredir deletes the allure-results folder on every run, taking the history data with it. If you want Allure’s trend graphs, either copy allure-report/history into allure-results/history before running without --clean-alluredir, or build a CI/CD setup that carries history forward from artifacts.

📋 Summary

  • Allure is a two-step process: run pytest to generate result files → run allure generate to produce HTML
  • @allure.step displays each test operation in a nested hierarchy, making it easy to pinpoint where things went wrong
  • Auto screenshot attachment can be applied to all tests via the pytest_runtest_makereport hook in conftest.py
  • severity, epic, feature, and story decorators make report filtering much more powerful
  • GitHub Actions requires both continue-on-error: true and the Allure CLI setup action

Start by installing allure-pytest and the Allure CLI, then try the two-command flow: pytest --alluredir=allure-resultsallure serve allure-results. From there, add steps and screenshots incrementally to make your reports richer over time.

Copied title and URL