behave-kit

The Swiss-army knife for Behave — soft assertions, typed context, conditional skip, environment management, fixtures and more.

behave-kit is a set of independent, opt-in utilities that make Behave test suites more robust, readable, and maintainable. Each feature can be used standalone or wired automatically via behave_kit.setup().

Features at a glance

  • Soft assertions — collect multiple failures, report them all at once

  • TypedContext — schema-validated proxy over the Behave context

  • Conditional skip — skip steps by env, OS, or missing dependency

  • Environment variables — typed reads with defaults and validation

  • Data loading — CSV, JSON, YAML, XLSX with a single load_data() call

  • Fixtures — tag-based setup/teardown with dependency resolution

  • Context dump — automatic context snapshot on scenario failure

  • Step suggestions — “did you mean?” hints for undefined steps

  • Scoped attributes — automatic cleanup of context attributes per scenario

  • Conditional steps@when_if runs a step only when a condition holds

  • Class-based stepsstep_impl_base() defines steps as methods on a class

  • Custom parameter types — register converters for step parameters

  • Soft exception assertionsassert_soft_raises for expected exceptions

  • Data-driven steps@data_driven runs a step once per data row

  • Environment snapshotenv_snapshot isolates env var changes

  • Dict navigationget_path for dot-notation nested access

  • Time assertionsassert_under and @timed for deadline checks

  • Pollingwait_until for condition-based waiting with timeout

  • Temp workspacetemp_workspace for filesystem-isolated tests

  • Continue after failedcontinue_after_failed keeps scenarios running after a failed step

  • Sub-step executionrun_steps composes steps with outline substitution and state isolation

  • Automatic wiringsetup() / teardown() for zero-config adoption

Three adoption levels

Level 1 — Automatic wiring:

from behave_kit import setup, teardown

def before_all(context):
    setup(context, env="staging")

def after_scenario(context, scenario):
    teardown(context)

Level 2 — Cherry-pick:

from behave_kit import assert_soft, env, load_data

@then("the response should be valid")
def step(context):
    assert_soft(context.response.status_code == 200)
    api_key = env("API_KEY", required=True)
    users = load_data("tests/data/users.csv")

Level 3 — Namespace:

import behave_kit as bk

@then("the response should be valid")
def step(context):
    bk.assert_soft(context.response.status_code == 200)

Installation

pip install behave-kit

With optional extras:

pip install "behave-kit[yaml,excel,dotenv]"

License

MIT — see LICENSE.