Fundamentals 7 min read

Using Pytest and Allure for UI Automation Testing and Report Generation

This article introduces pytest and Allure, explains how to write simple UI automation test cases with pytest, integrate Allure for attractive test reports, and provides step‑by‑step commands for generating and viewing the reports, making automated testing accessible for beginners.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Using Pytest and Allure for UI Automation Testing and Report Generation

Recently our team started a virtual group to perform UI automation testing using the pytest framework together with the Allure reporting framework, which together can produce standardized, well‑formatted, and visually appealing test reports.

1. Introduction to pytest

Pytest is a third‑party Python testing framework built on top of unittest. According to its official website, pytest is easy to get started with, supports both simple unit tests and complex functional tests, offers parameterization, allows skipping or marking expected failures, supports re‑running failed cases, can run tests written for nose or unittest, provides many third‑party plugins, and integrates smoothly with CI tools.

2. Writing pytest test cases

Test files should be named with a test_ prefix (or _test suffix). Test classes start with Test and must not define an __init__ method. Test functions start with test_ . Assertions are written using the built‑in assert statement.

3. Introduction to Allure

Allure is a lightweight, flexible open‑source test report generation framework that supports many testing tools such as TestNG, Pytest, and JUnit. In this guide we use the pytest-allure-adaptor plugin to integrate Allure with pytest.

Installation steps for pytest-allure-adaptor are shown, followed by downloading the Allure command‑line tool from the Bintray repository, extracting it, and adding its bin directory to the system PATH . JDK environment configuration is also required.

In test scripts, import Allure with import allure and use its features such as @allure.feature , @allure.story , with allure.step('description'): to add steps, and allure.attach() to attach additional data to the report.

4. Generating Allure test reports

Run the tests and generate Allure result files with the command:

py.test test_directory --alluredir=./allure-result

Then serve the report using:

allure serve test_directory

The generated report displays an overview page with counts of passed, failed, and skipped tests, environment details, suites, and features by stories. The Behaviors page groups test cases by features and stories, while the Suites page allows drilling down into individual test case execution steps and failure reasons.

Finally, the article concludes that combining Allure with pytest makes creating Allure‑style test reports straightforward and encourages readers to continue exploring testing techniques.

AutomationUI testingpytestAllureTest Reporting
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

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.