The pytest-bdd-report plugin is a useful extension for the pytest-bdd library that allows you to generate useful and informative reports for BDD (Behavior-Driven Development) tests developed using the pytest-bdd framework. This plugin facilitates the generation of clear and effective HTML reports, providing a comprehensible view of BDD test executions within the project.
For more, check out the Documentation
This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.
Features
Detailed BDD Reports: The pytest-bdd-report plugin enables the generation of detailed reports for BDD tests executed using pytest-bdd. These reports clearly show the executed steps, tested scenarios, and obtained results.
HTML Format: The generated reports are presented in an intuitive and interactive HTML format. This allows developers, testers, and other team members to easily view the status of BDD tests.
Easy Installation: Installing the plugin is simple and fast. You can install it using the command pip install pytest-bdd-report.
Requirements
Jinja2
pytest
pytest-bdd
Installation
Ensure that you have pytest and pytest-bdd installed in your development environment.
Open a terminal window.
Execute the following command to install the pytest-bdd-report plugin via pip from PyPI
$ pip install pytest-bdd-report
Usage
Once installed, you can generate BDD reports in an HTML file using the following command:
$ pytest --bdd-report="report.html"
Attach a screenshot to the HTML report generated by pytest-bdd-report, by using the provided attach.screenshot() method.
This helper function lets you attach screenshots either from raw bytes (e.g. page.screenshot() in Playwright) or from a file path on disk. The screenshot will automatically appear inside the corresponding Feature → Scenario section of the final report.
Example with Playwright
from pytest_bdd_report import attach
@pytest.hookimpl(hookwrapper=True)
def pytest_bdd_step_error(request, feature, scenario, step, step_func, step_func_args, exception):
yield
for fixture in step_func_args.values():
page = getattr(fixture, "page", None)
if page:
# Attach screenshot from bytes
screenshot_bytes = page.screenshot()
attach.screenshot(screenshot_bytes, feature.name, scenario.name) # pytest-bdd-report code to attach the screenshot
# Attach screenshot from image path
screenshot_path = "screenshot_path/test.png"
page.screenshot(path=screenshot_path)
attach.screenshot(screenshot_path, feature.name, scenario.name) # pytest-bdd-report code to attach the screenshot
Parameters
Parameter |
Type |
Description |
|---|---|---|
image |
bytes | str | Path |
Screenshot content. Can be raw bytes or a file path to the image to attach. |
feature_name |
str |
The name of the feature to which the screenshot belongs. |
scenario_name |
str |
The name of the scenario to which the screenshot belongs. |
Run tests
To run tests:
Create a virtual environment
Install the required packages:
$ pip install -r requirements.txt $ playwright install
Install the plugin locally:
$ pip install -e .
Run the unit tests:
$ python -m pytest --ignore=tests/bdd/
Run the BDD UI tests with pytest-bdd:
$ python -m pytest tests/bdd
Want a report for the Playwright BDD tests? use the –bdd-report flag!
$ python -m pytest tests/bdd --bdd-report="report.html"
Contributing
Contributions are very welcome. Tests can be run with pytest as shown.
License
Distributed under the terms of the MIT license, “pytest-bdd-report” is free and open source software
Issues
If you encounter any problems, please file an issue along with a detailed description.
Metadata
Release files for pytest-bdd-report 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_bdd_report-1.2.2.tar.gz | 29.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_bdd_report-1.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 70.3 kB
Release files / pytest_bdd_report-1.2.2.tar.gz
| Download URL | pytest_bdd_report-1.2.2.tar.gz |
|---|---|
| Size | 29.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebb6e205a9967f3f9c4c383b652d7fb5871a99658c63e1a17757661e73841ee3
|
|
BLAKE2b-256 checksum How to use checksums |
7d6c1bc54346c2d6139e15b4b825d00be717a853a840eb49684e6ff99a715c05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pytest_bdd_report-1.2.2-py3-none-any.whl
| Download URL | pytest_bdd_report-1.2.2-py3-none-any.whl |
|---|---|
| Size | 40.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2ac4c1e09cb0d0b68718f6897d00fa1ad1268234ca023d24c7b5e45cb9859213
|
|
BLAKE2b-256 checksum How to use checksums |
c0f601fc8f5d65a31d7c00cc2fb41e21657e5c0250e5abce14d8126b6346bdec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|