Registry / testing / pytest-reporter

pytest-reporter

JSON →
library0.5.3pypypi✓ verified 85d ago

pytest-reporter is a Pytest plugin that enables the generation of highly customizable test reports using templates. It provides the data context from a Pytest session, allowing users to create various text-based reports like HTML, LaTeX, or CSV by implementing their own rendering logic. The library is actively maintained with a regular release cadence, often addressing compatibility with new `pytest` versions and enhancing report data.

pip install pytest-reporter
INSTALL
IMPORT
SIG · PYTEST-REPORTER
P
pytest-reporter
testingpythonv0.5.3
Install
2.7s avg
Import
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 30.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.7s · import 0.000s · 31MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

version
from pytest_reporter import version
from jinja2 import Environment, FileSystemLoader, TemplateNotFound

To get started, create a `templates` directory with a Jinja2 HTML template (e.g., `my_report.html`). Then, in your `conftest.py`, implement the `pytest_reporter_render` hook to define how templates are loaded and rendered. Finally, run `pytest` from your project root, specifying the template directory, template file, and output report path using command-line options.

# File: conftest.py from jinja2 import Environment, FileSystemLoader, TemplateNotFound def pytest_reporter_render(template_name, dirs, context): """This hook is called to render a report template.""" env = Environment(loader=FileSystemLoader(dirs)) try: template = env.get_template(template_name) except TemplateNotFound: # Let other template plugins handle it if not found here return None return template.render(context) # File: templates/my_report.html <!-- Example Jinja2 template --> <!DOCTYPE html> <html> <head><title>Pytest Report</title></head> <body> <h1>Test Report</h1> <p>Started: {{ started|strftime('%Y-%m-%d %H:%M:%S') }}</p> <p>Total tests: {{ tests|length }}</p> <ul> {% for test in tests %} <li>{{ test.item.nodeid }} - Status: {{ test.status.word }} {% if test.phases %} <ul> {% for phase in test.phases %} <li>Phase: {{ phase.name }} - Status: {{ phase.status.word }}</li> {% endfor %} </ul> {% endif %} </li> {% endfor %} </ul> </body> </html> # File: test_example.py def test_success(): assert True def test_failure(): assert False # To run and generate report (from project root): # pytest --template-dir=templates --template=my_report.html --report=report.html
Debug
Known issues
breakingThe `function_context` fixture was removed in version 0.5.0. Any custom template or plugin relying on this fixture will break.
fix
Review and update custom code to remove dependencies on `function_context`. Use other available context objects like `config` or `session.tests`.
affects: 0.5.0+
breakingThe internal `pytest_warning_captured` hook was replaced by `pytest_warning_recorded` in version 0.5.0. Plugins implementing the older hook will cease to function correctly.
fix
Update any custom plugins or `conftest.py` implementations to use `pytest_warning_recorded` instead.
affects: 0.5.0+
gotchaThe plugin provides data to templates but does not include a rendering engine (like Jinja2) by default. Users must implement the `pytest_reporter_render` hook in `conftest.py` and provide their own template engine integration.
fix
Ensure `jinja2` or your chosen templating engine is installed (`pip install jinja2`) and that `pytest_reporter_render` is correctly implemented in your `conftest.py` to handle template loading and rendering.
affects: All versions
gotchaWhen using `pytest-xdist` for parallel execution, the `tests[].phases[].call` item within the template context may be optional or absent for some phases. Accessing it without a check can lead to `KeyError`.
fix
Templates should include checks (e.g., `{% if phase.call %}` in Jinja2) before attempting to access `phase.call` to ensure compatibility with `pytest-xdist`.
affects: 0.4.0+
breakingVersion 0.5.3 replaced the use of `pkg_resources`. While this was a fix, environments or custom extensions that implicitly relied on `pytest-reporter`'s previous `pkg_resources` usage might encounter compatibility issues.
fix
This change primarily affects internal workings. Users experiencing unexpected environment issues post-upgrade should verify their `pytest` and related plugin versions. Ensure compatibility with `pytest`'s own dependency changes.
affects: 0.5.3+
Upgrade
Version history
0.5.3latest on PyPI · released Feb 28, 2024
Audit
Dependencies
pytestrequiredCore testing framework that this plugin extends.
pytest-xdistoptionalFor parallel test execution; affects the availability of some report context data (e.g., 'call' information).
jinja2optionalA common template engine used for rendering reports; not strictly required by pytest-reporter but necessary for most custom HTML/text reports.
Agent activity
10 hits · last 30 days
node
8
Amazon
1
Resources
pytest-reporter — pip install pytest-reporter · libregistry