Continue After Failed¶
Control whether scenarios keep executing remaining steps after a step fails.
By default, Behave stops a scenario at the first failing step. This is
useful for fast failure feedback, but it hides downstream problems that
would only surface after the failing step. continue_after_failed
flips the default so the full scenario runs and every failure is
reported — ideal for comprehensive test reports and CI diagnostics.
How it works¶
The feature sets the class-level attribute
Scenario.continue_after_failed_step which Behave checks before
aborting a scenario on step failure. When set to True, Behave
records the failure and continues with the next step.
Global toggle¶
- behave_kit.continue_after_failed.continue_after_failed(enabled: bool = True) None[source]
Set whether scenarios continue executing after a failed step.
Sets the class-level attribute
Scenario.continue_after_failed_stepwhich Behave checks before aborting a scenario on step failure.- Parameters:
enabled – When
True, scenarios keep running remaining steps even after a step fails. WhenFalse, execution stops at the first failing step (Behave’s default).- Raises:
BehaveKitError – If
enabledis not a boolean.
Examples¶
from behave_kit import continue_after_failed
# Enable globally — every scenario continues after a failed step.
continue_after_failed(True)
# Disable (restore Behave's default behaviour).
continue_after_failed(False)
The setting applies to all scenarios that run while it is enabled.
Temporary toggle with continue_on_failure¶
- behave_kit.continue_after_failed.continue_on_failure() Iterator[None][source]
Temporarily enable continue-after-failed for the current block.
Sets
Scenario.continue_after_failed_steptoTrueon entry and restores the previous value on exit, even if an exception occurs.Usage:
with continue_on_failure(): # any scenario that runs while inside this block # will continue after failed steps ...
Use it as a context manager to scope the change to a block of code:
from behave_kit import continue_on_failure
with continue_on_failure():
# Any scenario that runs inside this block will continue
# after failed steps.
run_feature("features/smoke.feature")
# Outside the block, the previous setting is restored, even if
# an exception was raised inside the ``with`` block.
Wiring through setup()¶
Pass continue_after_failed=True to behave_kit.setup() to enable
it as part of the automatic wiring:
from behave_kit import setup
def before_all(context):
setup(context, continue_after_failed=True)
When wired through setup(), behave_kit.teardown() resets
Scenario.continue_after_failed_step to False at the end of the
run so the setting does not leak between test sessions.
Interaction with soft assertions¶
continue_after_failed and soft assertions are complementary:
Soft assertions collect multiple assertion failures within a single step and report them together.
Continue after failed lets the scenario keep running after a step fails, so you see failures across multiple steps.
Combined, they give you the most complete picture of what is broken in a scenario.
Validation¶
continue_after_failed() validates that enabled is a boolean,
preventing silent falsy values like None or 0 from being
interpreted as False:
from behave_kit import continue_after_failed
from behave_kit._core.errors import BehaveKitError
try:
continue_after_failed(None) # type: ignore[arg-type]
except BehaveKitError:
# Raises: "enabled must be a boolean, got NoneType"
pass