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

utils.mddocs/

Utility Functions

Helper functions for processing Behave scenarios, steps, and extracting metadata for Allure reports. These utilities handle status conversion, parameter extraction, naming conventions, and test organization.

Capabilities

Scenario Processing Functions

Functions for extracting and processing information from Behave scenario objects:

def scenario_name(scenario):
    """
    Extract display name from scenario.
    
    Parameters:
    - scenario: Behave scenario object
    
    Returns:
    str: Scenario name or scenario keyword if name is empty
    """

def scenario_history_id(scenario):
    """
    Generate unique history ID for scenario tracking across test runs.
    
    Parameters:
    - scenario: Behave scenario object
    
    Returns:
    str: MD5 hash of feature name, scenario name, and parameters
    """

def scenario_parameters(scenario):
    """
    Extract parameters from scenario outline table rows.
    
    Parameters:
    - scenario: Behave scenario object with optional _row attribute
    
    Returns:
    list[Parameter] | None: List of Parameter objects or None if no table
    """

def scenario_links(scenario, issue_pattern, link_pattern):
    """
    Extract links from scenario and feature tags.
    
    Parameters:
    - scenario: Behave scenario object
    - issue_pattern (str): Pattern for formatting issue links (e.g., "https://jira.com/browse/{}")
    - link_pattern (str): Pattern for formatting custom links
    
    Returns:
    filter: Filtered iterator of Link objects from parsed tags
    """

def scenario_labels(scenario):
    """
    Extract labels from scenario and feature tags.
    
    Parameters:
    - scenario: Behave scenario object
    
    Returns:
    list[Label]: Deduplicated list of Label objects including default severity
    """

def scenario_status(scenario):
    """
    Determine overall scenario status from step results.
    
    Parameters:
    - scenario: Behave scenario object with all_steps attribute
    
    Returns:
    Status: PASSED if all steps passed, otherwise first failing step status
    """

def scenario_status_details(scenario):
    """
    Get detailed status information from first failing step.
    
    Parameters:
    - scenario: Behave scenario object with all_steps attribute
    
    Returns:
    StatusDetails | None: Status details from first failing step or None
    """

Step Processing Functions

Functions for processing Behave step execution results:

def step_status(result):
    """
    Convert Behave step result to Allure status.
    
    Parameters:
    - result: Behave result object with status and exception attributes
    
    Returns:
    Status: Corresponding Allure Status enum value
    """

def step_status_details(result):
    """
    Extract detailed status information from step result.
    
    Parameters:
    - result: Behave result object with exception and traceback info
    
    Returns:
    StatusDetails | None: Detailed error information or implementation snippets
    """

def step_table(step):
    """
    Convert step table to CSV format for attachment.
    
    Parameters:
    - step: Behave step object with table attribute
    
    Returns:
    str: CSV formatted table with headers and rows
    """

Status Conversion Functions

Functions for converting Python exceptions and Behave statuses to Allure format:

def get_status(exception):
    """
    Convert Python exception to Allure status.
    
    Parameters:
    - exception: Python exception object or None
    
    Returns:
    Status: FAILED for AssertionError, BROKEN for other exceptions, PASSED for None
    """

def get_status_details(exc_type, exception, exc_traceback):
    """
    Create StatusDetails from exception information.
    
    Parameters:
    - exc_type: Exception type
    - exception: Exception instance
    - exc_traceback: Exception traceback
    
    Returns:
    StatusDetails | None: Formatted exception details or None
    """

Test Organization Functions

Functions for generating test names and organizing test results:

def get_fullname(scenario):
    """
    Generate full test name combining feature and scenario names.
    
    Parameters:
    - scenario: Behave scenario object with feature reference
    
    Returns:
    str: Formatted as "Feature Name: Scenario Name" (without parameters)
    """

def get_title_path(scenario):
    """
    Generate hierarchical title path for test organization.
    
    Parameters:
    - scenario: Behave scenario object with filename and feature info
    
    Returns:
    list[str]: Path components including directory structure and feature name
    """

def get_hook_name(name, parameters):
    """
    Format hook names for display in reports.
    
    Parameters:
    - name (str): Hook name (e.g., "before_tag", "after_scenario")
    - parameters (dict): Hook parameters, may contain tag information
    
    Returns:
    str: Formatted hook name with tag information if applicable
    """

Test Plan Functions

Functions for handling Allure test plan integration:

def is_planned_scenario(scenario, test_plan):
    """
    Check if scenario should run based on Allure test plan.
    
    Parameters:
    - scenario: Behave scenario object
    - test_plan: Allure test plan data or None
    
    Returns:
    None: Modifies scenario in-place, skipping it if not in test plan
    
    Side Effects:
    - Calls scenario.skip() with TEST_PLAN_SKIP_REASON if not planned
    - Uses scenario fullname and @allure.id labels for matching
    """

Constants

TEST_PLAN_SKIP_REASON = "Not in allure test plan"
"""Constant string used as skip reason for test plan filtering."""

STATUS = {
    'passed': Status.PASSED,
    'failed': Status.FAILED,
    'skipped': Status.SKIPPED,
    'untested': Status.SKIPPED,
    'undefined': Status.BROKEN
}
"""Mapping dictionary from Behave status strings to Allure Status enum values."""

Usage Examples

Custom Status Processing

from allure_behave.utils import step_status, step_status_details

def custom_step_processor(step_result):
    status = step_status(step_result)
    details = step_status_details(step_result)
    
    if status == Status.BROKEN:
        # Handle broken steps specially
        print(f"Broken step: {details.message}")
    
    return status, details

Scenario Metadata Extraction

from allure_behave.utils import (
    scenario_name, scenario_parameters, 
    scenario_labels, scenario_links
)

def analyze_scenario(scenario):
    name = scenario_name(scenario)
    params = scenario_parameters(scenario)
    labels = scenario_labels(scenario) 
    links = list(scenario_links(scenario, 
                               issue_pattern="https://jira.com/browse/{}", 
                               link_pattern="https://wiki.com/{}"))
    
    print(f"Scenario: {name}")
    if params:
        print(f"Parameters: {[p.name + '=' + p.value for p in params]}")
    print(f"Labels: {[l.name + '=' + l.value for l in labels]}")
    print(f"Links: {[l.url for l in links]}")

Test Organization

from allure_behave.utils import get_fullname, get_title_path

def organize_test_results(scenario):
    fullname = get_fullname(scenario)
    title_path = get_title_path(scenario)
    
    # Create hierarchical test organization
    return {
        'id': fullname,
        'path': title_path,
        'category': title_path[-1]  # Feature name
    }

Custom Test Plan Processing

from allure_behave.utils import is_planned_scenario

def apply_custom_test_plan(scenarios, test_plan):
    """Apply test plan to scenarios with custom logic."""
    for scenario in scenarios:
        # Apply standard test plan logic
        is_planned_scenario(scenario, test_plan)
        
        # Add custom filtering logic
        if hasattr(scenario, 'tags'):
            if 'slow' in scenario.tags and not os.getenv('RUN_SLOW_TESTS'):
                scenario.skip(reason="Slow tests disabled")

Type Definitions

from allure_commons.model2 import Parameter, Label, Link, StatusDetails, Status

class Parameter:
    """Test parameter with name and value."""
    name: str
    value: str

class Label:
    """Test label for categorization and filtering."""  
    name: str
    value: str

class Link:
    """External link associated with test."""
    type: str
    url: str
    name: str

class StatusDetails:
    """Detailed test/step status information."""
    message: str
    trace: str

class Status:
    """Allure test status enumeration."""
    PASSED = "passed"
    FAILED = "failed" 
    BROKEN = "broken"
    SKIPPED = "skipped"

Install with Tessl CLI

npx tessl i tessl/pypi-allure-behave

docs

formatter.md

hooks.md

index.md

listener.md

utils.md

tile.json