2016-12-06 5 views
0

私の振る舞いのステップは多かれ少なかれ類似したグループです。 私は提案をすることができますようにしたいと思います。定義されていない手順では、どのように役立つエラーが表示されますか?

例:

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

テストステップ

Given a cookie with icing 

で私は「私はどこかのパターン をハードコーディングすることを期待振舞う

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 

ような何かを言うためにクッキーをしたいと思いますクッキーステップを実装する関数へのマッピングが含まれます。 私は--steps-catalogの機能を再利用したいと思っていますが、doc文字列を使用するだけでOKです。

ありがとうございます!

答えて

0

これは実際には可能なことではありません。おそらく、あなたはこのような何か行うことができ、けれども:

@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() 

これがチェックした後は、別のステップを呼び出すことができますいずれかを、私はあなた次第、このいずれかを残しておきますので、あなたがこの時点を過ぎて物事を扱うことができ、非常にいくつかの方法があります。

関連する問題