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

listener.mddocs/

Event Processing

The AllureListener class handles the core test execution event processing, converting Behave's test lifecycle events into Allure report data. It manages test sessions, scenarios, steps, and attachments.

Capabilities

AllureListener Class

Core event processor that implements the allure_commons hook interface to capture and convert Behave test execution events into Allure report format.

class AllureListener:
    def __init__(self, behave_config):
        """
        Initialize the Allure listener with Behave configuration.
        
        Parameters:
        - behave_config: Behave configuration object containing test settings
                        and userdata for Allure configuration options
        
        Attributes:
        - issue_pattern (str): Pattern for formatting issue links from tags
        - link_pattern (str): Pattern for formatting custom links from tags  
        - hide_excluded (bool): Whether to hide tests excluded by test plan
        """
    
    def start_file(self):
        """
        Start processing a new feature file.
        Creates a new group context for organizing test results.
        """
    
    def stop_feature(self):
        """
        Complete processing of a feature file.
        Exits the current group context and finalizes feature results.
        """
    
    def start_scenario(self, scenario):
        """
        Start processing a scenario, creating Allure test case.
        
        Parameters:
        - scenario: Behave scenario object with name, tags, and metadata
        
        Creates:
        - TestResult object with scenario metadata
        - Scenario name, full name, and history ID
        - Parameters from scenario outline tables
        - Links and labels from scenario and feature tags
        """
    
    def stop_scenario(self, scenario):
        """
        Complete processing of a scenario.
        
        Parameters:
        - scenario: Behave scenario object with execution results
        
        Handles:
        - Test plan filtering and scenario exclusion
        - Status determination from step results
        - Final test result reporting or dropping
        """
    
    def schedule_step(self, step):
        """
        Schedule a step for execution tracking.
        
        Parameters:
        - step: Behave step object to be tracked
        """
    
    def match_step(self, match):
        """
        Process step match with step definition and start step execution.
        
        Parameters:
        - match: Behave match object linking step to implementation
        """
    
    def start_behave_step(self, step):
        """
        Start processing a Behave step, creating Allure step.
        
        Parameters:
        - step: Behave step object with keyword, name, text, and table
        
        Creates:
        - TestStepResult with step name and timing
        - Text attachments for step text content
        - CSV attachments for step tables
        """
    
    def stop_behave_step(self, result):
        """
        Complete processing of a Behave step.
        
        Parameters:
        - result: Behave result object with status, duration, and exceptions
        
        Handles:
        - Status determination from result
        - Exception details and stack traces
        - Step timing and final reporting
        """
    
    def flush_steps(self):
        """
        Process any remaining unmatched steps.
        Used for scenarios that end without all steps being matched.
        """
    
    def stop_session(self):
        """
        End the test session and finalize all reporting.
        Exits the root group context.
        """

Allure Commons Hook Implementations

The AllureListener also implements hooks from the allure_commons system for advanced Allure features:

def start_fixture(self, parent_uuid, uuid, name, parameters):
    """
    Start an Allure fixture (before/after hooks).
    
    Parameters:
    - parent_uuid (str): UUID of parent test or group
    - uuid (str): Unique identifier for this fixture
    - name (str): Fixture name (e.g., "before_scenario", "after_feature")
    - parameters (dict): Fixture parameters
    """

def stop_fixture(self, parent_uuid, uuid, name, exc_type, exc_val, exc_tb):
    """
    Complete an Allure fixture.
    
    Parameters:
    - parent_uuid (str): UUID of parent test or group
    - uuid (str): Fixture identifier
    - name (str): Fixture name
    - exc_type, exc_val, exc_tb: Exception information if fixture failed
    """

def start_test(self, parent_uuid, uuid, name, parameters, context):
    """
    Start an Allure test (wraps start_scenario).
    
    Parameters:
    - parent_uuid (str): Parent group UUID
    - uuid (str): Test UUID
    - name (str): Test name
    - parameters (dict): Test parameters
    - context (dict): Test context containing scenario object
    """

def stop_test(self, parent_uuid, uuid, name, context, exc_type, exc_val, exc_tb):
    """
    Complete an Allure test (wraps stop_scenario).
    
    Parameters:
    - parent_uuid (str): Parent group UUID
    - uuid (str): Test UUID  
    - name (str): Test name
    - context (dict): Test context containing scenario object
    - exc_type, exc_val, exc_tb: Exception information if test failed
    """

def start_step(self, uuid, title, params):
    """
    Start an Allure step with parameters.
    
    Parameters:
    - uuid (str): Step UUID
    - title (str): Step title/name
    - params (dict): Step parameters
    """

def stop_step(self, uuid, exc_type, exc_val, exc_tb):
    """
    Complete an Allure step.
    
    Parameters:
    - uuid (str): Step UUID
    - exc_type, exc_val, exc_tb: Exception information if step failed
    """

def attach_data(self, body, name, attachment_type, extension):
    """
    Attach data to current test or step.
    
    Parameters:
    - body: Data to attach (bytes or string)
    - name (str): Attachment name
    - attachment_type: Allure attachment type
    - extension (str): File extension for attachment
    """

def attach_file(self, source, name, attachment_type, extension):
    """
    Attach file to current test or step.
    
    Parameters:
    - source (str): Path to file to attach
    - name (str): Attachment name  
    - attachment_type: Allure attachment type
    - extension (str): File extension for attachment
    """

def add_description(self, test_description):
    """
    Add description to current test.
    
    Parameters:
    - test_description (str): Plain text description
    """

def add_description_html(self, test_description_html):
    """
    Add HTML description to current test.
    
    Parameters:
    - test_description_html (str): HTML formatted description
    """

def add_link(self, url, link_type, name):
    """
    Add link to current test.
    
    Parameters:
    - url (str): Link URL
    - link_type: Allure link type (ISSUE, LINK, etc.)
    - name (str): Link display name
    """

GroupContext Class

Internal helper class for managing test result container hierarchies:

class GroupContext:
    def __init__(self, logger):
        """
        Initialize group context manager.
        
        Parameters:
        - logger: AllureReporter instance for result logging
        """
    
    def enter(self):
        """
        Enter a new group context level.
        Creates a new TestResultContainer for organizing results.
        """
    
    def exit(self):
        """
        Exit the current group context level.
        Finalizes the current container and removes it from the stack.
        """
    
    def current_group(self):
        """
        Get the current group container.
        
        Returns:
        TestResultContainer: Current group for organizing results
        """
    
    def append_test(self, uuid):
        """
        Add a test to all current group containers.
        
        Parameters:
        - uuid (str): Test UUID to add to containers
        """

Configuration

The AllureListener reads configuration from behave's userdata:

# Configuration is passed via behave command line or behave.ini
# -D AllureFormatter.issue_pattern=https://jira.company.com/browse/{}
# -D AllureFormatter.link_pattern=https://docs.company.com/{}  
# -D AllureFormatter.hide_excluded=true

Test Metadata Extraction

The listener automatically extracts metadata from Behave elements:

  • Scenario Names: Uses scenario name or keyword as fallback
  • Parameters: From scenario outline table rows
  • Links: From @issue.ABC-123 and @link.DOC-456 style tags
  • Labels: From @severity.high, @tag.smoke style tags
  • History ID: MD5 hash of feature name, scenario name, and parameters
  • Full Names: Combined feature and scenario names for identification

Error Handling

The listener handles various error scenarios:

  • Undefined Steps: Creates status details with implementation snippets
  • Failed Steps: Captures exception messages and stack traces
  • Skipped Scenarios: Handles test plan filtering and tag-based skipping
  • Parallel Execution: Uses thread-local storage for state management

Install with Tessl CLI

npx tessl i tessl/pypi-allure-behave

docs

formatter.md

hooks.md

index.md

listener.md

utils.md

tile.json