Skip to content

Pipeline

The formatting pipeline consists of four stages applied in order: normalize → sort → align → print. Each stage operates on the behave-model Project in place.

Normalize

Cleans whitespace, standardizes indentation, normalizes tag names (ensures @ prefix), strips trailing whitespace from comments, and ensures table cells are stripped. This stage never changes semantics.

behave_format.pipeline.normalize

Normalize stage — clean whitespace and standardize structure.

This stage operates on a behave-model Project in place. It NEVER changes semantics: only whitespace, indentation, and structural consistency are normalized.

normalize_project

normalize_project(project: Project) -> Project

Normalize whitespace and structure across the entire project.

Parameters:

Name Type Description Default
project Project

The project to normalize (mutated in place).

required

Returns:

Type Description
Project

The same project, normalized.

Source code in behave_format/pipeline/normalize.py
def normalize_project(project: Project) -> Project:
    """Normalize whitespace and structure across the entire project.

    Args:
        project: The project to normalize (mutated in place).

    Returns:
        The same project, normalized.
    """
    for feature in project.features:
        _normalize_feature(feature)
    return project

Sort

Orders tags, features, and scenarios. By default only tags are sorted alphabetically. Feature and scenario sorting are opt-in via Settings.

behave_format.pipeline.sort

Sort stage — order tags, features, and scenarios.

Sorting is configurable via Settings. By default only tags are sorted alphabetically. Feature and scenario sorting are opt-in.

sort_project

sort_project(project: Project, settings: Settings) -> Project

Apply sorting rules to the project.

Parameters:

Name Type Description Default
project Project

The project to sort (mutated in place).

required
settings Settings

Formatter settings controlling sort behavior.

required

Returns:

Type Description
Project

The same project, sorted.

Source code in behave_format/pipeline/sort.py
def sort_project(project: Project, settings: Settings) -> Project:
    """Apply sorting rules to the project.

    Args:
        project: The project to sort (mutated in place).
        settings: Formatter settings controlling sort behavior.

    Returns:
        The same project, sorted.
    """
    if settings.sort_tags:
        _sort_all_tags(project)

    if settings.sort_features:
        project.features.sort(key=lambda f: f.name)

    if settings.sort_scenarios:
        for feature in project.features:
            _sort_feature_scenarios(feature)

    return project

Align

Ensures tables are rectangular (pads short rows, extends headers when a row has extra cells) and removes trailing whitespace. This stage operates on the model before printing and never drops cell values.

behave_format.pipeline.align

Align stage — table alignment and trailing whitespace removal.

This stage ensures tables are properly aligned and no trailing whitespace remains in any text content. It operates on the model before printing.

align_project

align_project(project: Project) -> Project

Apply alignment rules to the project.

Parameters:

Name Type Description Default
project Project

The project to align (mutated in place).

required

Returns:

Type Description
Project

The same project, aligned.

Source code in behave_format/pipeline/align.py
def align_project(project: Project) -> Project:
    """Apply alignment rules to the project.

    Args:
        project: The project to align (mutated in place).

    Returns:
        The same project, aligned.
    """
    for feature in project.features:
        _align_feature(feature)
    return project

align_feature

align_feature(feature: Feature) -> Feature

Apply alignment rules to a single feature.

Parameters:

Name Type Description Default
feature Feature

The feature to align (mutated in place).

required

Returns:

Type Description
Feature

The same feature, aligned.

Source code in behave_format/pipeline/align.py
def align_feature(feature: Feature) -> Feature:
    """Apply alignment rules to a single feature.

    Args:
        feature: The feature to align (mutated in place).

    Returns:
        The same feature, aligned.
    """
    _align_feature(feature)
    return feature