0

My behave steps are more or less groups with variations. I would like to be able to give suggestions.

example:

@given('a cookie with sprinkles')
def cookie_with_sprinkles():
   """Given a cookie with sprinkles"""
   ...
@given('a cookie with icing')
   ...
@given('a cookie in wrapping')
   ...

With the test step

Given a cookie with icing

I would like behave to say something like

Undefined step 'Given a cookie with icing'
Steps available with 'a cookie' are:
  Given a cookie with sprinkles
  Given a cookie with icing
  Given a cookie in wrapping

I expect to hardcode somewhere a pattern 'a cookie' and the mapping to the functions implementing cookie steps. I would love re-using the functionality from --steps-catalog, but just using the doc string would be ok.

Thanks!

Verv
  • 2,385
  • 2
  • 23
  • 37
Mary Bergman
  • 98
  • 1
  • 5

1 Answers1

0

This isn't really possible as is, except probably by patching Behave itself. Although, perhaps you could do something like this:

@given('a cookie with {what}')
def cookie_with_something(context, what):
    """defines all my cookie steps"""

    # here we define the available choices
    choices = ['sprinkles', 'icing', 'wrapping']

    # and if our step selected an invalid choice, we throw
    # an exception and list the available choices
    # you may as well just exit the step without raising
    # an exception, up to you
    if what not in choices:

        print("Undefined step 'Given a cookie with %s" % what)
        print("Steps available with 'a cookie' are:")

        for choice in choices:

            print("    Given a cookie with %s" % choice)

        raise AssertionError()

After this check you could either call another step, there's quite a few ways you could handle things past this point so I'll leave this one up to you.

Verv
  • 2,385
  • 2
  • 23
  • 37