Pytest plugin that generates rich HTML test reports with step tracking, log capture, and interactive filtering
Project description
💡 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
stepcontext manager or decorator (sync and async); supports nested steps with automatic hierarchical numbering (1,1.1,1.2,2, …) - ✅ 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_nameFixture — override the displayed test name at runtime (useful for parameterised tests) - ✅ Async Support —
stepworks as bothasync withand anasync defdecorator
⚙️ 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
- Install the plugin:
uv add pytest-reporter-html - Enable HTML report generation by adding
--report-htmlto your pytest options - Run your tests normally with
pytest - Open
logs/test-reports/TestReport_Latest.htmlin any browser - (Optional) Use
stepto 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 1: Create user PASSED 120ms
├── Step 2: Update profile PASSED 45ms
└── Step 3: Verify changes PASSED 30ms
Example 2: Nested steps
Steps can be nested to any depth. Each level gets a hierarchical number automatically (1.1, 1.2, 2.1, …).
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("Assign default role"):
logger.info("Setting role to 'viewer'")
with step("Send welcome email"):
logger.info("Email dispatched")
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 1: Create user PASSED 120ms
│ ├── Step 1.1: Assign default role PASSED 30ms
│ └── Step 1.2: Send welcome email PASSED 20ms
├── Step 2: Update profile PASSED 45ms
└── Step 3: Verify changes PASSED 30ms
Sub-steps appear visually indented inside their parent step in the HTML report.
Example 3: 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 1: Fetch user data
assert user["active"] is True
Example 4: 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
🤝 Contributing
If you have a helpful pattern or improvement to suggest:
- Fork the repo
- Create a new branch
- 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!
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 pytest_reporter_html-2.3.0.tar.gz.
File metadata
- Download URL: pytest_reporter_html-2.3.0.tar.gz
- Upload date:
- Size: 98.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
580de56f0d70bc9147e4406ca5fa5e94488e2b9b83db695e44412e3b97c7e1f9
|
|
| MD5 |
5f74a9ca0fd87163b2925a0dc475d780
|
|
| BLAKE2b-256 |
308a85f593757c711f731f196477336ee8a2d4ea53b4073278157d060ae50e89
|
File details
Details for the file pytest_reporter_html-2.3.0-py3-none-any.whl.
File metadata
- Download URL: pytest_reporter_html-2.3.0-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3275416e9aa5b51b5f213f0ab8d6b6a9c46bae801d3f987899219bfb523d2774
|
|
| MD5 |
85246c9c13b4ae73d19d49f6b28d0085
|
|
| BLAKE2b-256 |
54cf88215cbcc44e5fa6d3d3e41b52d94834582a602978b90e43c9b2987e0381
|