I did what you are trying to do, take a screenshot of the failed test by setting the hook after_stepto my file environment.py.
def after_step(context, step):
if step.status == "failed":
take_the_shot(context.scenario.name + " " + step.name)
, , , .
, , behave step context , , scenario feature . before_step, , context.step.name. - :
def before_step(context, step):
context.step = step
:
def step_impl(context):
if some_condition:
take_the_shot(context.scenario.name + " " + context.step.name)