Fundamentals 9 min read

Customizing Allure Test Reports with Pytest – A Step‑by‑Step Tutorial

This tutorial explains how to install Allure‑pytest, create a simple Dianping search test case, generate the default report, and progressively enhance it with custom titles, detailed steps, fixture‑based setup/teardown, hierarchical features, severity levels, and rich HTML descriptions, all using Python code snippets.

FunTester
FunTester
FunTester
Customizing Allure Test Reports with Pytest – A Step‑by‑Step Tutorial

The Allure Framework is a lightweight, multi‑language test report generator that presents test results in an elegant web UI. By integrating Allure with Pytest, teams can extract valuable status information from each test run.

Environment setup : install the latest Python, then run the following commands to add the required packages:

pip3 install pytest
pip3 install allure-pytest

Use pip3 list to verify the installed versions.

Test scenario : a simple Dianping homepage and search test is used as a demo. Two test points are defined – homepage title assertion and search result title assertion – each implemented as a separate Pytest function.

Generating the default Allure report :

pytest --alluredir=results

After execution, JSON files are created in the specified directory. To view a temporary web report, run:

allure serve results

To generate a permanent HTML report:

allure generate results -o allure-report

Customizing test case titles – replace the default method‑name titles with meaningful ones:

@allure.title("Validate Dianping homepage title")
@allure.title("Validate {txt} search result title")

Adding detailed steps with with allure.step("step description") makes each action visible in the report.

Setup/teardown via fixtures : move browser initialization and closure into a pytest.fixture(scope="class") and use it in a test class, reducing redundancy.

Hierarchical grouping and severity :

@allure.feature('Dianping page tests')
@allure.story('Dianping homepage')
@allure.severity('critical')

and similarly for the search test with @allure.story('Dianping search') and @allure.severity('blocker') .

Rich description – embed HTML in the report using @allure.description_html(""" Validate Dianping homepage title Test steps Open Chrome and navigate to Dianping Capture homepage title Assert the title """) .

All these customizations are demonstrated across incremental script versions (V1.0 to V1.5), with screenshots showing the evolving report UI.

PythonautomationpytestAllureTest ReportingAllure Customization
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.