Skip to main content

Pytest plugin that generates rich HTML test reports with step tracking, log capture, and interactive filtering

Project description

PyPI version Python Development Status Maintenance PyPI License


💡 pytest-reporter-html

A pytest plugin that automatically generates rich, interactive HTML test reports with zero-config log capture, named step tracking, exception rendering, and real-time filtering — open the file in any browser and start debugging.


📦 Installation

uv add pytest-reporter-html

🚀 Features

  • Zero-Config Log Capture — attaches to Python's root logger automatically; every logging.*() call is captured as a report event without any code changes
  • Named Steps — group events into collapsible, timed steps using the step context manager or decorator (sync and async)
  • Automatic Phase Steps — Setup, test body, and Teardown phases are created automatically for every test
  • Interactive HTML Report — real-time search, status filter (Passed/Failed), log-level filter (TRACE→ERROR), expand/collapse all, progress bar
  • Exception Rendering — full tracebacks captured and rendered as collapsible blocks; failed tests auto-expand
  • JSON + HTTP Visualisation — embedded JSON is syntax-highlighted; HTTP requests are shown with a generated cURL command and copy button
  • Per-Test JSON Files — one structured JSON file per test; usable by other tools independently of the HTML
  • report_test_name Fixture — override the displayed test name at runtime (useful for parameterised tests)
  • Async Supportstep works as both async with and an async def decorator

⚙️ Configuration

Enable the HTML report by adding --report-html to your pytest options:

# pytest.ini
[pytest]
addopts =
    --report-html
    --output-dir=logs

Or pass it directly on the command line:

pytest --report-html

Output directory

The default output directory is logs/test-reports. Override it with --output-dir:

pytest --report-html --output-dir=build/reports

🛠️ How to Use

  1. Install the plugin: uv add pytest-reporter-html
  2. Enable HTML report generation by adding --report-html to your pytest options
  3. Run your tests normally with pytest
  4. Open logs/test-reports/TestReport_Latest.html in any browser
  5. (Optional) Use step to group log events into named, collapsible blocks

🚀 Quick Start

# pyproject.toml
[tool.pytest.ini_options]
addopts = "--report-html"
pytest

After the run, open the report:

logs/test-reports/TestReport_Latest.html

▶️ Usage Examples

Example 1: Named steps with logging

from custom_python_logger import get_logger
from pytest_reporter_html import step

logger = get_logger(__name__)

def test_user_lifecycle():
    with step("Create user"):
        logger.info("Creating a new user with role 'user'")

    with step("Update profile"):
        logger.info("Updating user profile to set role to 'admin'")

    with step("Verify changes"):
        logger.info("Verifying that the user's role has been updated to 'admin'")

Report output:

Test: test_user_lifecycle                                            PASSED
 ├── Step 01: Create user                               PASSED    120ms
 ├── Step 02: Update profile                            PASSED     45ms
 └── Step 03: Verify changes                            PASSED     30ms

Example 2: step as a decorator

from custom_python_logger import get_logger
from pytest_reporter_html import step

logger = get_logger(__name__)

@step("Fetch user data")
def get_user(user_id: str) -> dict:
    logger.info(f"Fetching user {user_id}")
    return {"id": user_id, "active": True}

@step("Send notification")
async def notify(user_id: str) -> None:
    logger.info(f"Sending notification to user {user_id}")

def test_flow():
    user = get_user("u-1")   # → Step 01: Fetch user data
    assert user["active"] is True

Example 3: Failure output

When a test fails it auto-expands in the report, showing the failure message, stack trace, and all log events up to the point of failure:

from custom_python_logger import get_logger
from pytest_reporter_html import step

logger = get_logger(__name__)

def test_order_checkout():
    with step("Create order"):
        logger.info("Creating order with 3 items")

    with step("Checkout"):
        logger.info("Submitting checkout request")
        assert False, "Checkout failed — payment declined"  # ← step is marked FAILED

🧑‍💻 HTML Report Example

Open HTML Report Example


🤝 Contributing

If you have a helpful pattern or improvement to suggest:

  1. Fork the repo
  2. Create a new branch
  3. Submit a pull request

Contributions that improve report quality, add new rendering formats, or extend CI integrations are welcome.


📄 License

MIT License — see LICENSE for details.


🙏 Thanks

Thanks for exploring this repository!
Happy coding!

GitHub   PyPI   LinkedIn

GitHub   PyPI   Blog   LinkedIn

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_reporter_html-2.2.0.tar.gz (97.1 kB view details)

Uploaded Source

Built Distribution

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

pytest_reporter_html-2.2.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest_reporter_html-2.2.0.tar.gz.

File metadata

  • Download URL: pytest_reporter_html-2.2.0.tar.gz
  • Upload date:
  • Size: 97.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_reporter_html-2.2.0.tar.gz
Algorithm Hash digest
SHA256 1d604a27fe07cc41e52637a746bc19e762e0f2704c9deb59c41cf720fb813470
MD5 54e68c4135d5223d7dbf8949acc6e7f7
BLAKE2b-256 fd3bb73ee5d3f0786059a65f2c802717a4568f4135c28ec9566f8321bdd94687

See more details on using hashes here.

File details

Details for the file pytest_reporter_html-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_reporter_html-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2060a3abefbacaddc3f6f7e24d4e29d5db6be02456a838e934f75e3768de7fc
MD5 d317017cbae513f7f96cf5b7871b4aad
BLAKE2b-256 2737c6bc25de42c55827e8fc28c4a91fb1f1991896871c73ce373225c56c034b

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