【问题标题】:When trying to run lettuce scenario with examples, the steps I have created fail to be recognized尝试使用示例运行生菜场景时,我创建的步骤无法被识别
【发布时间】:2013-02-28 20:26:36
【问题描述】:

让我看看能不能告诉你我有多困惑。

如果我只使用内联变量的生菜特征文件,一切正常。例如,如果我创建以下功能文件:

Feature: File Finder
    I need to just look for the presence of certain files on a system

Scenario Outline:  Verify the presence (or absence) of a file on a system
    Given I log into a system at "172.16.100.23" as user "cadmin" with password "cadmin"
    Then I can look for "/var/log/nginx.log" and know that it should "not" be there

然后运行生菜,它告诉我创建以下步骤:

You can implement step definitions for undefined steps with these snippets:

# -*- coding: utf-8 -*-
from lettuce import step

@step(u'Given I log into a system at "([^"]*)" as user "([^"]*)" with password "([^"]*)"')
def given_i_log_into_a_system_at_group1_as_user_group2_with_password_group2(step, group1, group2, group3):
    assert False, 'This step must be implemented'
@step(u'Then I can look for "([^"]*)" and know that it should "([^"]*)" be there')
def then_i_can_look_for_group1_and_know_that_it_should_group2_be_there(step, group1, group2):
    assert False, 'This step must be implemented'

如果我将该标题(“从生菜导入步骤”)和这些步骤粘贴到 filefinder.py 文件夹中,并将“assert False”更改为“assert True”以使测试通过,我将顺利通过:

Feature: File Finder
  I need to just look for the presence of certain files on a system

Scenario: Verify the presence (or absence) of a file on a system
  Given I log into a system at "172.16.100.23" as user "cadmin" with password "cadmin"
  Then I can look for "/var/log/nginx.log" and know that it should "not" be there

1 feature (1 passed)
1 scenario (1 passed)
2 steps (2 passed)

现在,我想添加一个示例表。我所做的只是添加Then I can ask <manager> for <item> 作为我的第三步和以下示例表:

Examples:
    | manager   | item            |
    | "bob"     | "raise"         |
    | "suzy"    | "more switches" |
    | "bill"    | "more coffee"   |

当我针对这个运行生菜时,它告诉我:

You can implement step definitions for undefined steps with these snippets:

# -*- coding: utf-8 -*-
from lettuce import step

@step(u'Then I can ask <manager> for <item>')
def then_i_can_ask_manager_for_item(step):
    assert False, 'This step must be implemented'

所以,我将它添加到我的 filefinder.py 文件中,并将“assert False”更改为“assert True”,只是为了让它通过并在我的控制台上看到绿色。如果我对此运行生菜,它会给我完全相同的响应,就好像它无法将占位符 &lt;manager&gt;&lt;item&gt; 识别为创建有效步骤一样,我猜。这是我唯一一次无法创建它要求的步骤 - 当我使用此处所述的占位符时:http://lettuce.it/tutorial/scenario-outlines.html 奇怪的是,该示例显示“场景大纲:阶乘 [0-4]”,因为我可以t 判断是否需要 [0-4]。尽管我没有任何成功的示例测试,但在我的测试中似乎没有任何区别,所以我可能完全错了。

我需要做的是弄清楚为什么 lettuce 看不到那些内联有“&lt;placeholder&gt;”语法的步骤。

有人可以帮我解释一下吗?

【问题讨论】:

    标签: python continuous-integration lettuce


    【解决方案1】:

    我看到了这个页面:http://lettuce.it/intro/wtf.html 恰当地命名为 wtf!

    我需要做的是在 &lt;placeholders&gt; 周围加上引号并删除示例表中的引号。

    现在,我的功能文件如下所示:

    Feature: File Finder
        I need to just look for the presence of certain files on a system
    
    Scenario Outline:  Verify the presence of a file on a system [0-3]
        Given I log into a system at "172.16.100.23" as user "cadmin" with password "cadmin"
        Then I can look for "/var/log/nginx.log" and know that it should "not" be there
        Then I can ask "<manager>" for "<item>"
    
    Examples:
        | manager | item          |
        | bob     | raise         |       
        | suzy    | more switches |
        | bill    | more coffee   |
    

    它在我的控制台上以各种绿色通过:

    Feature: File Finder
      I need to just look for the presence of certain files on a system
    
    Scenario Outline: Verify the presence of a file on a system
      Given I log into a system at "172.16.100.23" as user "cadmin" with password "cadmin"
      Then I can look for "/var/log/nginx.log" and know that it should "not" be there
      Then I can ask "<manager>" for "<item>"
    
    Examples:
      | manager | item          |
      | bob     | raise         |
      | suzy    | more switches |
      | bill    | more coffee   |
    
    1 feature (1 passed)
    3 scenarios (3 passed)
    9 steps (9 passed)
    

    要点...“[0-4]”不是必需的,在使用示例时,请确保使用“场景大纲”而不是“场景”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 2021-12-28
      • 2017-03-27
      • 2021-09-06
      • 1970-01-01
      • 2021-11-17
      相关资源
      最近更新 更多