Skip to main content

A pytest-bdd plugin for generating useful and informative BDD test reports

Project description

Python versions PyPI version GitHub Workflow Status (with event)

GitHub Workflow Status (with event) GitHub Workflow Status (with event) GitHub Workflow Status (with event)

PePy total downloads

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

  1. Ensure that you have pytest and pytest-bdd installed in your development environment.

  2. Open a terminal window.

  3. 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:

  1. Create a virtual environment

  2. Install the required packages:

$ pip install -r requirements.txt
$ playwright install
  1. Install the plugin locally:

$ pip install -e .
  1. Run the unit tests:

$ python -m pytest --ignore=tests/bdd/
  1. Run the BDD UI tests with pytest-bdd:

$ python -m pytest tests/bdd
  1. 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.

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_bdd_report-1.2.2.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

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

pytest_bdd_report-1.2.2-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest_bdd_report-1.2.2.tar.gz.

File metadata

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

File hashes

Hashes for pytest_bdd_report-1.2.2.tar.gz
Algorithm Hash digest
SHA256 ebb6e205a9967f3f9c4c383b652d7fb5871a99658c63e1a17757661e73841ee3
MD5 3dfc03e1df1591ad76f42a686532c56f
BLAKE2b-256 7d6c1bc54346c2d6139e15b4b825d00be717a853a840eb49684e6ff99a715c05

See more details on using hashes here.

File details

Details for the file pytest_bdd_report-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_bdd_report-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2ac4c1e09cb0d0b68718f6897d00fa1ad1268234ca023d24c7b5e45cb9859213
MD5 09e91b6b9dc3d3e3d31d4f820bd8de53
BLAKE2b-256 c0f601fc8f5d65a31d7c00cc2fb41e21657e5c0250e5abce14d8126b6346bdec

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