Allure pytest integration
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
- breaking Older versions of `allure-pytest` (pre-2.14.3) may not correctly handle `allure.title` for fixtures when used with `pytest` version 8.4 or later.
- gotcha If you were previously using `pytest-allure-adaptor`, it must be uninstalled before installing `allure-pytest` due to conflicting implementations. The `allure-pytest` setup process will explicitly check for this conflict.
- breaking As of `allure-python` 2.14.0, official support for Python 3.7 has been dropped. Users on Python 3.7 will not receive updates or fixes for newer `allure-pytest` versions.
- gotcha The Allure Report command-line tool (required to generate and serve HTML reports) is a separate installation from `allure-pytest` and requires a Java Runtime Environment (JRE) to function.
- gotcha In versions prior to 2.15.0, reports for tests defined within nested classes might have incorrect `fullName`, `historyId`, `testCaseId`, and `subSuite` values, leading to improper grouping and history tracking.
- gotcha As of version 2.14.3, built-in (reserved) `pytest` markers are no longer converted into Allure tags. If your reporting workflow relied on these markers appearing as tags, this behavior has changed.
Install
-
pip install allure-pytest
Imports
- allure
import allure
- LabelType
from allure_commons.types import LabelType
Quickstart
# 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