Formatter¶
The formatter module is the main orchestrator for the formatting pipeline. It provides four public functions that cover the two main operations: format (mutate in place) and render (format + produce text).
Module Reference¶
behave_format.pipeline.formatter
¶
Formatter — the main orchestrator for the formatting pipeline.
The pipeline is
- Normalize — clean whitespace, standardize structure
- Sort — order tags, features, scenarios
- Align — table alignment, trailing whitespace
- Print — convert model to .feature text
format_project
¶
Format a behave-model Project in place.
Applies the full pipeline: normalize → sort → align. The project is mutated and returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Project
|
The project to format. |
required |
settings
|
Settings | None
|
Optional formatter settings. Defaults to Settings(). |
None
|
Returns:
| Type | Description |
|---|---|
Project
|
The same project, formatted. |
Source code in behave_format/pipeline/formatter.py
format_feature
¶
Format a single Feature in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Feature
|
The feature to format. |
required |
settings
|
Settings | None
|
Optional formatter settings. Defaults to Settings(). |
None
|
Returns:
| Type | Description |
|---|---|
Feature
|
The same feature, formatted. |
Source code in behave_format/pipeline/formatter.py
render_feature
¶
Format and render a Feature as .feature text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Feature
|
The feature to format and print. |
required |
settings
|
Settings | None
|
Optional formatter settings. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The formatted .feature file content as a string. |
Source code in behave_format/pipeline/formatter.py
render_project
¶
Format and render an entire Project as .feature text.
Features are separated by a single blank line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Project
|
The project to format and print. |
required |
settings
|
Settings | None
|
Optional formatter settings. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The formatted content for all features, joined by blank lines. |
Source code in behave_format/pipeline/formatter.py
Functions¶
format_project¶
Applies the full pipeline (normalize → sort → align) to a behave-model Project. The project is mutated and returned.
from behave_format import format_project, Settings
from behave_model import load_project
project = load_project("features/")
format_project(project, Settings(indent=4))
render_project¶
Formats the project and returns the formatted .feature text for all features, joined by blank lines.
from behave_format import render_project
from behave_model import load_project
project = load_project("features/")
text = render_project(project)
print(text)
format_feature¶
Formats a single Feature in place. Applies normalization and tag sorting. Alignment is handled at print time.
render_feature¶
Formats a single feature and returns the formatted .feature file content as a string.