Skip to main content

Enhanced HTML reporting for pytest with categories, specifications, and detailed logging

Project description

pytest-html-report

PyPI version Python versions License: MIT

Source Code

GitLab

Features

  • ✅ Structured HTML reports with categorization
  • ✅ Support for functional specifications and test categories
  • ✅ Detailed test execution logs with step-by-step tracking
  • ✅ Report theme and metadata customization

Installation

pip install pytest-html-report

Usage

Basic Configuration

Create a pytest_html_report.yml file in your project root:

report:
  title: "My Test Report"
  img_url: "https://your-logo-url.png"
  report_dir: "reports"
  test_environment: "Development"

functional_specs:
  SPEC-001: "User Authentication"
  SPEC-002: "Data Processing"
  SPEC-003: "API Integration"

categories:
  unit: "Unit Tests"
  integration: "Integration Tests"
  regression: "Regression Tests"

Writing Tests

Use the provided markers to add metadata to your tests:

import pytest

@pytest.mark.reporting(
    developer="John Doe",
    functional_specification="SPEC-001",
    test_description="Validate user login flow"
)
@pytest.mark.category("integration", "regression")
def test_user_login(logger):
    """Test user authentication process"""
    logger.step("Setting up test data")
    # Test implementation
    logger.step("Validating results")
    assert True

@pytest.mark.reporting(
    developer="Jane Smith",
    functional_specification=["SPEC-002", "SPEC-003"],
    test_description="Complex data pipeline test"
)
@pytest.mark.category("integration")
def test_data_pipeline(logger):
    """Test data processing pipeline"""
    logger.step("Initializing pipeline")
    # Test implementation
    logger.step("Verifying output")
    assert 1 == 1
    # Test assertions
    logger.assertion("Output 1 matches expected result 1")

Running Tests

Run your tests with pytest as usual:

pytest 

The HTML report will be generated in the configured report directory (default: reports/). The report name is the report_date_time.html, e.g., reports/report_20250622_231929.html.

Example Report Output

Report Overview Test Categories Test Details Test Results

Available Markers

  • @pytest.mark.reporting: Add metadata about the test

    • developer: Test owner/developer
    • functional_specification: Link to functional specs
    • test_description: Brief description of the test
  • @pytest.mark.category: Categorize tests

    • Multiple categories can be specified

Logging Steps

The plugin provides a logger fixture for detailed test steps:

def test_example(logger):
    logger.step("Starting test preparation")
    # Test setup
    logger.step("Executing main test logic")
    # Test execution
    logger.assertion("Asserting result 1 == 1")
    # Assertions

Customizing Report Theme

You can customize the report appearance in your config:

theme:
  primary_color: "#0052CC"
  success_bg: "#E3FCEF"
  error_bg: "#FFEBE6"
  warning_bg: "#FFFAE6"
  info_bg: "#DEEBFF"

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

pytest_html_report-1.0.3.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

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

pytest_html_report-1.0.3-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_html_report-1.0.3.tar.gz.

File metadata

  • Download URL: pytest_html_report-1.0.3.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pytest_html_report-1.0.3.tar.gz
Algorithm Hash digest
SHA256 05c78b4b6f44aead3baf86e4fe14fb4a0480fef31d196b34f1bdb6f8d1621834
MD5 b69d548f4c9ce79452bc461c7c6514f1
BLAKE2b-256 ce8e2f9a3033115a28c29926c2d4960aaa0addcd2bfb8ca878ac04aec8e649e1

See more details on using hashes here.

File details

Details for the file pytest_html_report-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_html_report-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7b4ca04bdcf2758bdb2374ab17ec69444aaeba4baa443e29aaa3147fd59b4b24
MD5 6a05c2dff77cc7983d3aa44eb4b8c646
BLAKE2b-256 1d15a5618c9419ead6f5b57e85830f8fdc6e4ba53aba508ab3636c458c2450be

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