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().
Getting Started
Features
Reference
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()callFixtures — 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_ifruns a step only when a condition holdsClass-based steps —
step_impl_base()defines steps as methods on a classCustom parameter types — register converters for step parameters
Soft exception assertions —
assert_soft_raisesfor expected exceptionsData-driven steps —
@data_drivenruns a step once per data rowEnvironment snapshot —
env_snapshotisolates env var changesDict navigation —
get_pathfor dot-notation nested accessTime assertions —
assert_underand@timedfor deadline checksPolling —
wait_untilfor condition-based waiting with timeoutTemp workspace —
temp_workspacefor filesystem-isolated testsContinue after failed —
continue_after_failedkeeps scenarios running after a failed stepSub-step execution —
run_stepscomposes steps with outline substitution and state isolationAutomatic wiring —
setup()/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.