Generating Test Reports with PyTest and Allure
In automated testing, generating clear and informative test reports is essential for understanding test results, identifying failures, and communicating with stakeholders. PyTest, a powerful Python testing framework, can be integrated with Allure, a flexible reporting tool, to produce beautiful and detailed test reports.
Here's a step-by-step guide to generating test reports using PyTest and Allure.
What is Allure?
Allure is an open-source framework designed to create interactive and visually rich test reports. It shows test results in a readable format with:
- Steps and logs
- Screenshots
- Attachments
- Timelines and test history
Install Required Packages
Make sure Python and PyTest are installed, then install Allure-related packages:
pip install pytest allure-pytest
You also need to download Allure Commandline from the official site and add it to your system path.
Write Sample PyTest Script
Create a test file like test_sample.py:
import pytest
import allure
@allure.title("Test for addition")
@allure.description("Verify if 2 + 2 equals 4")
def test_addition():
assert 2 + 2 == 4
@allure.title("Test for division")
@allure.description("Verify division by zero")
def test_divide_by_zero():
with pytest.raises(ZeroDivisionError):
result = 1 / 0
Run Tests and Generate Allure Results
Run your tests with the following command to generate results:
pytest --alluredir=allure-results
This creates a folder allure-results that stores raw data for the report.
Generate Allure Report
Now use the Allure CLI to generate the HTML report:
- allure generate allure-results -o allure-report --clean
- To open the report in a browser:
- allure open allure-report
Report Features
Allure test reports provide:
Overview Dashboard – pass/fail stats, history, environment
Detailed Test Cases – with descriptions, logs, and screenshots
Timeline View – to analyze parallel test execution
Categories and Suites – organize tests for better readability
Conclusion
Combining PyTest with Allure helps testers produce clean, comprehensive, and interactive test reports. It improves visibility into test results and makes debugging much easier. If you're looking to enhance your test reporting in Python automation, Allure is a great choice to add to your workflow.
Learn Selenium Python Training in Hyderabad
Read More:
Validating Links and Images Using Selenium
Automating Captcha: What You Can and Can't Do
Selenium with Python: Common Errors and Fixes
Using Page Object Model (POM) with Python Selenium
Automating Web Forms with Multiple Steps
Visit our IHub Talent Training Institute
Comments
Post a Comment