Search code examples
pythonbddpython-behave

Read current step string on behave


I'd like to read the current step string that is matched. In behave, once the match is done, it runs the function that is tagged with the matching step string. I'd like to print this step string. How would I be able to do such a simple task?

Example:

@given("x is equal to 4")
def step_impl(context):
    # Here I would like to print the string: 'x is equal to 4'

Solution

  • There is a lot of interesting info in the context. (See the docs.) The current step can be found in context.scenario.steps[0].name.