Skip to content

Configuration

behave-gen reads configuration from the [tool.behave-gen] table in pyproject.toml. All options have sensible defaults — configuration is optional.

Default configuration

# pyproject.toml
[tool.behave-gen]
features_dir = "features"
steps_dir = "features/steps"
environment_file = "environment.py"
templates_dir = "templates"
template_engine = "string"
default_tags = []

Options

Option Type Default Description
features_dir str "features" Directory containing .feature files.
steps_dir str "features/steps" Directory containing step definitions.
environment_file str "environment.py" Path to the environment hooks file.
templates_dir str "templates" Directory for custom templates.
template_engine str "string" Template engine: "string" or "jinja2".
default_tags str or list[str] [] Tags applied to all generated features.

Template engine

The default string engine uses Python's string.Template with $variable substitution. It has no extra dependencies.

[tool.behave-gen]
template_engine = "string"

For advanced templating with conditionals, loops, and filters, use Jinja2:

[tool.behave-gen]
template_engine = "jinja2"

Requires the jinja2 extra:

pip install behave-gen[jinja2]

See ADR-0003 for the rationale.

Default tags

Tags in default_tags are applied to every feature generated by behave-gen add feature:

[tool.behave-gen]
default_tags = ["@smoke", "@regression"]

Tags passed via --tags on the CLI are combined with default_tags.

Custom templates

Place custom templates in the templates_dir directory. Feature templates must be .feature files using the configured template engine.

With string engine:

${tags}Feature: $feature_name
  Description for $feature_name.

  Scenario: $feature_name scenario
    Given a precondition for $feature_name

With jinja2 engine:

{{ tags }}Feature: {{ feature_name }}
  Description for {{ feature_name }}.

  Scenario: {{ feature_name }} scenario
    Given a precondition for {{ feature_name }}

CLI overrides

CLI flags always override config file values. The --config global option points to an explicit pyproject.toml config file. When omitted, the pyproject.toml in the project root is used by default.

behave-gen --config /path/to/pyproject.toml add feature login