Analyze and summarize Allure test reports
Project description
Allure Report Summarizer
A Python utility for analyzing and summarizing Allure test reports. This tool extracts detailed test execution statistics, timing information, and test status data from Allure HTML reports, providing comprehensive insights into test suite performance.
Features
- Test Execution Statistics: Extracts total, passed, failed, broken, skipped, and unknown test counts
- Timing Analysis: Provides start time, stop time, and duration of test executions
- Pass Rate Calculation: Automatically calculates test suite pass rates
- Unique Test Tracking: Identifies and counts unique test cases by status
- JSON Export: Saves failed and passed test IDs to separate JSON files for further analysis
- Multiple Output Formats: Supports both console output and file-based summaries
- Robust File Handling: Handles various file encodings (UTF-8, Latin1, CP1252, ISO-8859-1)
- Environment Configuration: Configurable via environment variables
Installation
Requirements
- Python 3.6+
- Allure HTML report files
Install from PyPI
pip install allure-report-analyzer
Set environment variables
# Set the path for JSON output files (default: c:\reports\json_files)
export JSON_FILE_PATH="path/to/your/json/output"
# Set the Allure report directory path
export ALLURE_REPORT_PATH="path/to/allure/reports"
Usage
Command Line Usage
After installation, you can use the command-line tool:
# Set the path to your Allure reports
export ALLURE_REPORT_PATH="/path/to/allure/reports"
# Run the summarizer
allure-analyzer
Or run directly with Python:
python -c "from allure_report_summarizer import summarize_allure_report; summarize_allure_report()"
The script will:
- Find the first HTML file in the specified directory
- Process the Allure report
- Display summary statistics
- Save failed and passed test IDs to JSON files
Python API Usage
from report_summarize import summarize_html_report, save_summary_to_file, get_unique_test_count
# Summarize a report
summary = summarize_html_report("path/to/report.html")
print(summary)
# Output:
# {
# 'start_time': '2024-03-01 10:00:00',
# 'stop_time': '2024-03-01 11:00:00',
# 'duration': '1 hours 0 minutes 0 seconds',
# 'total': 100,
# 'passed': 90,
# 'failed': 10,
# 'broken': 0,
# 'skipped': 0,
# 'unknown': 0,
# 'pass_rate': '90.00%'
# }
# Save summary to file
save_summary_to_file(summary, "report_summary.txt")
# Get detailed test statistics
test_stats = get_unique_test_count("path/to/report.html")
print(f"Failed tests: {len(test_stats['failed'])}")
print(f"Passed tests: {len(test_stats['passed'])}")
Advanced Usage
from report_summarize import (
get_report_path,
get_summary_message,
get_file_size_in_mb,
read_html_file,
extract_test_data
)
# Get the latest report file path
report_path = get_report_path("/path/to/reports")
# Read HTML content with encoding handling
content = read_html_file(report_path)
# Extract test data
test_data = extract_test_data(content)
# Get file size
size = get_file_size_in_mb(report_path)
print(f"Report size: {size}")
# Generate formatted message
summary = summarize_html_report(report_path)
message = get_summary_message(summary)
print(message)
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
ALLURE_REPORT_PATH |
Directory containing Allure HTML reports | Required (no default) |
JSON_FILE_PATH |
Directory for JSON output files | c:\reports\json_files |
Output Files
The script generates the following output files in the JSON_FILE_PATH directory:
failed_testscripts.json: List of failed test case IDspassed_testscripts.json: List of passed test case IDs
API Reference
Core Functions
summarize_html_report(report_path: str) -> Dict[str, Any]
Summarizes an Allure HTML report and returns statistics.
Parameters:
report_path: Path to the Allure HTML report file
Returns:
- Dictionary with test execution statistics
get_unique_test_count(html_file_path: str) -> Dict[str, List[str]]
Analyzes test results and returns unique test counts by status.
Parameters:
html_file_path: Path to the HTML report file
Returns:
- Dictionary with lists of test IDs by status
save_summary_to_file(summary: Dict[str, Any], file_path: str)
Saves summary data to a text file.
get_report_path(attachment_path: str) -> str
Gets the path to the latest report file in a directory.
Utility Functions
get_filename(directory: str) -> str
Gets the first HTML file found in a directory.
read_html_file(html_file: str) -> Optional[str]
Reads an HTML file with multiple encoding fallbacks.
extract_test_data(html_content: str) -> Optional[Dict]
Extracts test data from embedded JSON in HTML content.
get_file_size_in_mb(file_path: str) -> str
Returns file size in megabytes.
Error Handling
The module includes comprehensive error handling for:
- File not found errors
- Invalid JSON data
- Encoding issues
- Missing data fields
- Directory access problems
All errors are logged to console with descriptive messages.
Examples
Basic Report Analysis
from report_summarize import summarize_html_report
# Analyze a single report
summary = summarize_html_report("allure-report/index.html")
for key, value in summary.items():
print(f"{key}: {value}")
Batch Processing Multiple Reports
import os
from report_summarize import summarize_html_report
reports_dir = "/path/to/reports"
for filename in os.listdir(reports_dir):
if filename.endswith('.html'):
report_path = os.path.join(reports_dir, filename)
summary = summarize_html_report(report_path)
print(f"Report: {filename}")
print(f"Pass Rate: {summary['pass_rate']}")
Custom Output Formatting
from report_summarize import summarize_html_report, get_unique_test_count
report_path = "allure-report/index.html"
summary = summarize_html_report(report_path)
test_stats = get_unique_test_count(report_path)
print("=== TEST EXECUTION SUMMARY ===")
print(f"Duration: {summary['duration']}")
print(f"Total Tests: {len(test_stats['total'])}")
print(f"Passed: {len(test_stats['passed'])}")
print(f"Failed: {len(test_stats['failed'])}")
print(f"Pass Rate: {summary['pass_rate']}")
if test_stats['failed']:
print("\nFailed Test IDs:")
for test_id in test_stats['failed'][:10]: # Show first 10
print(f" - {test_id}")
if len(test_stats['failed']) > 10:
print(f" ... and {len(test_stats['failed']) - 10} more")
Dependencies
- Python 3.6+
- Standard library modules:
json,os,re,datetime,typing
License
[Specify your license here]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file allure_report_analyzer-1.0.2.tar.gz.
File metadata
- Download URL: allure_report_analyzer-1.0.2.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b15edc52baff3f24139fc98ec9623a83e4f1e65f15488f9f1c279d0bc9b8bf50
|
|
| MD5 |
9bfc9b4941a82b75f0c501fd0f52da04
|
|
| BLAKE2b-256 |
a15bd4cd52375d6f3b7e29d0071e4625caac8238d887cffbb57db6922fde6f42
|
File details
Details for the file allure_report_analyzer-1.0.2-py3-none-any.whl.
File metadata
- Download URL: allure_report_analyzer-1.0.2-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e820a11055b0b0fed168df959c4b963c7535faf94b3e3485247d9329de50e07
|
|
| MD5 |
71b2d3f6f485d6df5038f93bb62c4d55
|
|
| BLAKE2b-256 |
5702163ea2556f5743f11146d0664cd9ce1d1132c76c44479659ed8f81a53c1a
|