Metadata-Version: 2.4
Name: pytest-html-report-builder
Version: 0.1.0
Summary: A pytest plugin that generates self-contained HTML automation reports with visual charts.
Author: OpenAI Codex
License: MIT
Project-URL: Homepage, https://github.com/viduroberoi/pytest-html-report-builder
Project-URL: Repository, https://github.com/viduroberoi/pytest-html-report-builder
Project-URL: Issues, https://github.com/viduroberoi/pytest-html-report-builder/issues
Classifier: Framework :: Pytest
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: pytest>=7.0

# pytest-automation-report

`pytest-automation-report` is a lightweight pytest plugin that creates a self-contained HTML execution report after a test run. The report includes:

- summary cards for key test metrics
- outcome distribution charts
- execution phase timing charts
- slowest test visualizations
- module-level execution breakdown
- embedded failure screenshots
- failure details and a complete test result table

## Installation

```bash
pip install -e .
```

## Usage

Generate a report on demand:

```bash
pytest --automation-report=reports/automation-report.html
```

Customize the report title:

```bash
pytest \
  --automation-report=reports/automation-report.html \
  --automation-report-title="Nightly Regression Dashboard"
```

You can also configure a default output path in `pytest.ini`:

```ini
[pytest]
automation_report = reports/automation-report.html
automation_report_title = CI Automation Report
```

## What the Report Includes

- KPI summary cards for total tests, pass rate, total runtime, and average runtime
- a donut chart showing overall test outcomes
- a bar chart for total phase durations across setup, call, and teardown
- a bar chart for the slowest tests in the run
- a bar chart highlighting the busiest test modules
- embedded screenshots for failed UI tests
- failure cards with stack traces
- a detailed test results table

## Example Integration

Once installed, the plugin is discovered automatically by pytest through the `pytest11` entry point. That means your existing test suite can use it without changing test code.

If you prefer local plugin loading during development, you can also enable it explicitly:

```python
# conftest.py
pytest_plugins = ["pytest_automation_report.plugin"]
```

## Selenium Screenshot Support

The plugin supports screenshots in two ways:

- automatic capture on test failure when a Selenium-style fixture named `driver`, `browser`, `selenium`, or `webdriver` exposes `get_screenshot_as_base64()` or `get_screenshot_as_png()`
- manual screenshot attachment from the test itself through the `automation_report` fixture

### Automatic failure screenshots

If your test already uses a Selenium WebDriver fixture called `driver`, no extra code is required beyond generating the report:

```python
def test_checkout(driver):
    driver.get("https://example.com/checkout")
    assert "Success" in driver.page_source
```

When that test fails during the call phase, the plugin will try to capture a screenshot and embed it directly in the HTML report.

### Manual screenshot attachment

Use the built-in `automation_report` fixture when you want explicit control over what gets attached:

```python
def test_checkout(driver, automation_report):
    driver.get("https://example.com/checkout")

    if "Success" not in driver.page_source:
        automation_report(
            image_base64=driver.get_screenshot_as_base64(),
            name="Checkout failure state",
        )

    assert "Success" in driver.page_source
```

You can also attach raw bytes:

```python
automation_report(image_bytes=driver.get_screenshot_as_png(), name="Current page")
```

### Helper import option

If you prefer not to use the fixture, you can also call the helper directly:

```python
from pytest_automation_report.plugin import attach_screenshot


def test_checkout(driver, request):
    attach_screenshot(
        request,
        image_base64=driver.get_screenshot_as_base64(),
        name="Checkout failure state",
    )
```
