Printers¶
Printer modules convert behave-model objects into formatted Gherkin text. Each printer handles a specific model element and is responsible for indentation, alignment, and spacing.
Feature Printer¶
Formats a complete Feature — including tags, description, background, scenarios, scenario outlines, and rules — into a full .feature file string.
behave_format.printer.feature_printer
¶
Feature printer — formats a complete Feature as .feature text.
print_feature
¶
Format a Feature as valid, deterministic Gherkin text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Feature
|
The Feature to print. |
required |
indent
|
int
|
Base indentation for scenarios and rules. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string representing the complete feature file content. |
Source code in behave_format/printer/feature_printer.py
Scenario Printer¶
Formats Background, Scenario, and ScenarioOutline blocks, including their tags, descriptions, steps, and examples tables.
behave_format.printer.scenario_printer
¶
Scenario printer — formats scenarios and scenario outlines.
print_background
¶
Format a Background block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
background
|
Background
|
The Background to print. |
required |
indent
|
int
|
Base indentation level. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string with the background and its steps. |
Source code in behave_format/printer/scenario_printer.py
print_scenario
¶
Format a Scenario as Gherkin text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
Scenario
|
The Scenario to print. |
required |
indent
|
int
|
Base indentation level. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string with tags, scenario header, and steps. |
Source code in behave_format/printer/scenario_printer.py
print_scenario_outline
¶
Format a ScenarioOutline as Gherkin text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outline
|
ScenarioOutline
|
The ScenarioOutline to print. |
required |
indent
|
int
|
Base indentation level. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string with tags, outline header, steps, and examples. |
Source code in behave_format/printer/scenario_printer.py
Step Printer¶
Formats a Step with proper indentation, including attached DocString and data Table.
behave_format.printer.step_printer
¶
Step printer — formats steps with proper indentation.
print_step
¶
Format a single step as Gherkin text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Step
|
The Step to print. |
required |
indent
|
int
|
Number of spaces for indentation. |
4
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string with the step and any attached docstring or table. |
Source code in behave_format/printer/step_printer.py
Table Printer¶
Formats a Table with aligned columns. Computes column widths from headers and all rows to produce a rectangular, padded table.
behave_format.printer.table_printer
¶
Table printer — formats data tables with aligned columns.
print_table
¶
Format a Table as aligned Gherkin table text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
The Table to print. |
required |
indent
|
int
|
Number of spaces for indentation. |
4
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string with aligned table rows. |
Source code in behave_format/printer/table_printer.py
Tag Printer¶
Formats a list of Tag objects as a single space-separated string with optional indentation.
behave_format.printer.tag_printer
¶
Tag printer — formats tags as space-separated strings.
print_tags
¶
Format a list of tags as a single line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags
|
list[Tag]
|
List of Tag objects. |
required |
indent
|
int
|
Number of spaces to prefix. |
0
|
Returns:
| Type | Description |
|---|---|
str
|
A space-separated tag string, or empty string if no tags. |