CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-allure-behave

Allure behave integration that provides comprehensive test reporting and visualization for the Behave BDD testing framework

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

formatter.mddocs/

Formatter Integration

The AllureFormatter class provides the primary integration method for Allure Behave, implementing Behave's formatter interface to capture test execution events and generate Allure reports.

Capabilities

AllureFormatter Class

Main formatter class that extends Behave's base formatter to capture test execution events and generate comprehensive Allure reports.

class AllureFormatter:
    def __init__(self, stream_opener, config):
        """
        Initialize the Allure formatter.
        
        Parameters:
        - stream_opener: Behave's stream opener for output handling
        - config: Behave configuration object containing test settings
        """
    
    def uri(self, uri):
        """
        Process feature file URI when starting a new feature file.
        
        Parameters:
        - uri (str): Path to the feature file being processed
        """
    
    def feature(self, feature):
        """
        Process feature object and wrap scenarios for Allure integration.
        
        Parameters:
        - feature: Behave feature object containing scenarios and metadata
        """
    
    def step(self, step):
        """
        Schedule a step for execution tracking.
        
        Parameters:
        - step: Behave step object with keyword, name, and optional table/text
        """
    
    def match(self, match):
        """
        Process step match with step definition.
        
        Parameters:
        - match: Behave match object linking step to its implementation
        """
    
    def result(self, result):
        """
        Process step execution result.
        
        Parameters:
        - result: Behave result object with status, duration, and exception info
        """
    
    def eof(self):
        """
        Handle end of feature file processing.
        """
    
    def close(self):
        """
        Clean up formatter resources and unregister plugins.
        """
    
    def close_stream(self):
        """
        Stop the test session and finalize reporting.
        """

Usage Examples

Command Line Usage

The most common way to use the AllureFormatter is via behave command line:

# Basic usage - generate reports in 'allure_results' directory
behave -f allure_behave.formatter:AllureFormatter -o allure_results ./features

# With specific output directory
behave -f allure_behave.formatter:AllureFormatter -o /path/to/results ./features

# Combined with other formatters (e.g., pretty for console output)
behave -f pretty -f allure_behave.formatter:AllureFormatter -o allure_results ./features

# With behave configuration options
behave -f allure_behave.formatter:AllureFormatter -o results \
       -D AllureFormatter.issue_pattern=https://jira.example.com/browse/{} \
       -D AllureFormatter.link_pattern=https://docs.example.com/{} \
       ./features

Generating and Viewing Reports

After test execution, use Allure CLI to generate and serve reports:

# Generate static HTML report
allure generate allure_results -o allure_report --clean

# Serve report on local web server
allure serve allure_results

# Open generated report
allure open allure_report

Configuration Options

Configure the formatter behavior using behave's userdata mechanism:

# Issue link pattern - converts @issue.ABC-123 tags to clickable links
behave -f allure_behave.formatter:AllureFormatter -o results \
       -D AllureFormatter.issue_pattern=https://jira.company.com/browse/{}

# Custom link pattern - converts @link.DOC-456 tags to documentation links  
behave -f allure_behave.formatter:AllureFormatter -o results \
       -D AllureFormatter.link_pattern=https://docs.company.com/{}

# Hide tests excluded by test plan
behave -f allure_behave.formatter:AllureFormatter -o results \
       -D AllureFormatter.hide_excluded=true

Integration with CI/CD

Example Jenkins pipeline integration:

pipeline {
    agent any
    stages {
        stage('Test') {
            steps {
                sh 'behave -f allure_behave.formatter:AllureFormatter -o allure_results ./features'
            }
            post {
                always {
                    allure includeProperties: false, 
                           jdk: '', 
                           results: [[path: 'allure_results']]
                }
            }
        }
    }
}

Limitations

  • Parallel Execution: The formatter approach doesn't work with behave-parallel. Use Hooks Integration instead.
  • Custom Environment: If you need custom before/after hooks that interact with Allure, use the hooks approach.
  • Multiple Processes: Each process needs its own output directory to avoid conflicts.

Install with Tessl CLI

npx tessl i tessl/pypi-allure-behave

docs

formatter.md

hooks.md

index.md

listener.md

utils.md

tile.json