Allure Behave
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
- gotcha Generating the final HTML Allure Report requires the Allure Report command-line tool, which is a separate Java-based dependency and needs to be installed outside of Python (e.g., via Homebrew on macOS or manual download).
- gotcha When running Behave tests in parallel (e.g., with `behave-parallel` or `behavex`), using the formatter directly (`-f allure_behave.formatter:AllureFormatter`) might be incompatible or lead to missing features.
- gotcha The error `format=allure_behave.formatter:AllureFormatter is unknown` typically indicates that `allure-behave` is not correctly installed or not accessible in the Python environment where `behave` is being run.
- gotcha Using `AllureFormatter.hide_excluded=true` with tag-excluded scenarios can lead to steps from the excluded scenarios incorrectly bleeding into the results of the next matching scenario.
- breaking Older versions (pre-2.14.2) could produce `AttributeError` if `Allure Behave` was set up via `AllureHooks` or generate extra test results after consecutive in-process runs of `Behave`.
Install
-
pip install allure-behave -
brew install allure # For macOS # Or install via other package managers: https://allurereport.org/docs/gettingstarted-installation/
Imports
- AllureFormatter
behave -f allure_behave.formatter:AllureFormatter ...
- allure
import allure
- allure_report
from allure_behave.hooks import allure_report
Quickstart
# 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