Allure pytest integration

2.15.3 · active · verified Thu Apr 09

Allure pytest integration provides a way to integrate the Allure Test Reporting Framework with pytest tests. It functions as a pytest plugin, automatically collecting test results and generating comprehensive, interactive reports. The library is actively maintained as part of the `allure-python` monorepo, with frequent minor releases, typically on a monthly or bi-monthly basis.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic pytest test file with Allure decorators. To generate the Allure report, first run pytest with the `--alluredir` option to create XML results. Then, use the `allure serve` command (from the separately installed Allure command-line tool) to process these XML files and open an interactive HTML report in your browser. The Allure command-line tool requires Java.

# test_example.py
import allure
import pytest

@allure.epic("Web Testing")
@allure.feature("Login Functionality")
def test_successful_login():
    allure.dynamic.story("User can log in with valid credentials")
    with allure.step("Enter username and password"):
        print("Entering credentials...")
    with allure.step("Click login button"):
        print("Clicking login...")
    assert True

@allure.epic("API Testing")
@allure.feature("User Management")
def test_get_user_profile():
    allure.dynamic.story("Retrieve user data via API")
    with allure.step("Send GET request to user endpoint"):
        print("Sending request...")
    with allure.step("Verify response status code"):
        print("Checking status...")
    with allure.step("Validate user data in response"):
        print("Validating data...")
    assert True

# To run tests and generate Allure results:
# pytest --alluredir=allure-results

# To serve the Allure report (requires Allure command-line tool):
# allure serve allure-results

view raw JSON →