2015-10-19 23 views
-2

我有很多功能,並希望控制標籤列表,以防止錯字和其他命名問題。有沒有什麼方法可以在我的所有功能中獲得標籤列表?如何對我的功能中使用的所有標籤執行檢查?

因此,有

@opponent 
Feature: Fight or flight 
    In order to increase the ninja survival rate, 
    As a ninja commander 
    I want my ninjas to decide whether to take on an 
    opponent based on their skill levels 

    Scenario: Weaker opponent 
    Given the ninja has a third level black-belt 
    When attacked by a samurai 
    Then the ninja should engage the opponent 

    @wip 
    Scenario: Stronger opponent 
    Given the ninja has a third level black-belt 
    When attacked by Chuck Norris 
    Then the ninja should run for his life 

而且

Feature: showing off behave 

    @dummy 
    Scenario: run a simple test 
    Given we have behave installed 
    when we implement a test 
    then behave will test it for us! 

我得到的標籤['opponent', 'wip', 'dummy']列表。

回答

1

您可以通過在你的environment.py一個before_scenario掛鉤這將遍歷場景的標籤做到這一點:

​​

你會希望有一個類似鉤用於遍歷功能的標籤。

或者,如果你不在乎代碼是否連接到場景或功能,你可以使用一個before_tag掛鉤,而不是上述兩個掛鉤:

def before_tag(context, tag): 
    if tag not in (... tuple of valid values...): 
     raise ValueError("unexpected tag: " + tag) 
相關問題