Allure pytest-bdd integration

2.15.3 · active · verified Fri Apr 17

allure-pytest-bdd provides integration between the Allure reporting framework and pytest-bdd, allowing users to generate rich, interactive test reports for BDD scenarios written with Gherkin. It is part of the broader Allure Python ecosystem, currently at version 2.15.3, and receives frequent, usually minor, updates.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates a basic `pytest-bdd` scenario integrated with `allure-pytest-bdd`. It includes a feature file and a test file with step definitions. The `allure.step` and `allure.attach` calls show how to enhance the report. Running `pytest` with `--alluredir` generates the report data, which can then be served locally using the Allure commandline tool.

# features/example.feature
# Feature: Basic BDD scenario
#
#   Scenario: User logs in successfully
#     Given a user is on the login page
#     When the user enters valid credentials
#     Then the user should be redirected to the dashboard

# test_example.py
import pytest
import allure
from pytest_bdd import scenario, given, when, then

@scenario('features/example.feature', 'User logs in successfully')
def test_login():
    """This is the test for the login scenario."""
    pass

@given('a user is on the login page')
def login_page():
    allure.step("Navigated to login page")
    assert True

@when('the user enters valid credentials')
def enter_credentials():
    with allure.step("Entering username and password"):
        allure.attach("username: test_user", name="credentials", attachment_type=allure.attachment_type.TEXT)
    assert True

@then('the user should be redirected to the dashboard')
def dashboard_redirect():
    allure.dynamic.tag("login-flow")
    assert True

# To run tests and generate Allure report:
# pytest --alluredir=allure-results

# To open the report in your browser (requires Allure commandline):
# allure serve allure-results

view raw JSON →