Allure Behave

2.15.3 · active · verified Tue Apr 14

Allure behave is an adapter for Behave that integrates Behave tests with Allure Report, a flexible and lightweight multi-language test report tool. It enhances standard Behave reporting by providing capabilities for crafting more informative and structured tests, allowing for metadata annotation, test organization, step division, and attachment of files like screenshots. The current version is 2.15.3 and it generally follows the Allure Python project's release cadence, with frequent updates for bug fixes and new features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate Allure Behave with a simple Behave feature file and step definitions. It includes an example of using `@allure.step` for sub-steps and `allure.attach` for adding content to the report. The `behave.ini` configuration is shown as an alternative to command-line arguments for specifying the Allure formatter. Finally, it shows how to generate and view the interactive Allure report using the Allure Report CLI tool.

# 1. features/example.feature
Feature: Allure Behave Example
  Scenario: A simple test scenario
    Given I have a step
    When I perform an action
    Then I should see a result

# 2. steps/example_steps.py
from behave import given, when, then
import allure

@given('I have a step')
def step_have_step(context):
    pass

@when('I perform an action')
def step_perform_action(context):
    with allure.step('Sub-step: doing something important'):
        print('Performing action...')

@then('I should see a result')
def step_see_result(context):
    allure.attach('This is some attachment content.', name='Text Attachment', attachment_type=allure.attachment_type.TEXT)
    assert True

# 3. behave.ini (optional, but good practice)
# [behave]
# format=allure_behave.formatter:AllureFormatter
# outfiles=allure-results

# 4. Run Behave tests and collect results
# behave -f allure_behave.formatter:AllureFormatter -o allure-results features/

# 5. Generate and open the Allure Report
# allure serve allure-results

view raw JSON →