Skip to main content

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

Install from Source

  1. Clone the repository:
git clone <repository-url>
cd allure-report-summarize
  1. Install the package:
pip install .

Or for development:

pip install -e .
  1. (Optional) 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:

  1. Find the first HTML file in the specified directory
  2. Process the Allure report
  3. Display summary statistics
  4. 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 IDs
  • passed_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

allure_report_analyzer-1.0.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

allure_report_analyzer-1.0.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file allure_report_analyzer-1.0.1.tar.gz.

File metadata

  • Download URL: allure_report_analyzer-1.0.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for allure_report_analyzer-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8a58fa254cb6446233083bccf4f51700688b8ca94d9687b9cbf4e72e0855e039
MD5 fe04bcd911acfc809c1a6d6276d4b839
BLAKE2b-256 64652a7ed0ede1e4a9df36242d5f5bf2de039ebc429afac5daa65a78008c9f09

See more details on using hashes here.

File details

Details for the file allure_report_analyzer-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for allure_report_analyzer-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d30edf9d9cded941def70366d523a91122803358a3864334a5be734a44392a0d
MD5 456b45df847a814b5064d0446cd9f22e
BLAKE2b-256 a4f5c6fe95c43efffadaf213e54cc9fdb97ca2f1366d18d066fdf9c9c9778f3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page