【问题标题】:Python-behave tag's Or logic does not appear to be workingPython-behave 标记的 Or 逻辑似乎不起作用
【发布时间】:2020-05-26 16:28:51
【问题描述】:
Feature: Addition tests

@one
Scenario: Add two numbers to pass
  Given two numbers to add
  When 2 and 3 are added together
  Then the sum should be 5

@two
  Scenario: Add two numbers to fail
  Given two numbers to add
  When 2 and 3 are added together
  Then the sum should be 6

运行 >> 行为 --tags="@one" (或行为 --tags=one) 给我

@one
Scenario: Add two numbers to pass  # features/Add.feature:4
  Given two numbers to add         # features/steps/Maths.py:4 0.000s
  When 2 and 3 are added together  # features/steps/Maths.py:8 0.000s
  Then the sum should be 5         # features/steps/Maths.py:12 0.000s

 @two
 Scenario: Add two numbers to fail  # features/Add.feature:10
   Given two numbers to add         # None
   When 2 and 3 are added together  # None
   Then the sum should be 6         # None

正如预期的那样。

An yet Running >> 行为 --tags="@one or @two" 给我

@one
Scenario: Add two numbers to pass  # features/Add.feature:4
  Given two numbers to add         # None
  When 2 and 3 are added together  # None
  Then the sum should be 5         # None

@two
Scenario: Add two numbers to fail  # features/Add.feature:10
  Given two numbers to add         # None
  When 2 and 3 are added together  # None
  Then the sum should be 6         # None

这应该执行两个场景,并且根据每个教程,这似乎是运行多个场景的方式。我是否在这里遗漏了一些明显的东西(而且我肯定在运行“或”而不是行为 --tags="@one and @two")?

【问题讨论】:

    标签: python bdd python-behave


    【解决方案1】:

    虽然 latest version 文档中记录了此功能,但 stable version 中不提供此功能,在撰写此答案时为 1.2.6。您的问题已在 github and closed 中记录了一段时间。

    您可能安装了 1.2.6 或更低版本,在这种情况下,您应该使用以下之一进行逻辑 OR:

    behave --tags=one,two
    
    #that's the same thing as
    behave --tags @one,@two
    

    behave --tags-help 也提供了一些有用的信息。

    如果您想升级,请卸载当前的behave 版本并安装最新的可用标记版本(此时为 v1.2.7.v1)。

    sudo pip uninstall behave
    pip install git+https://github.com/behave/behave@v1.2.7.v1
    

    说明和其他安装选项here。

    【讨论】:

    • 0buz - 非常感谢。绝对的救星!我确实在使用 1.2.6。我一直在写一些可笑的复杂标签和场景来解决这个问题。但没有更多了。
    【解决方案2】:

    没有答案,我还不能发表评论。

    我也有类似的问题。

    behave --tags="@one and @two"

    运行 "and" ^^^ 似乎会跳过所有测试,即使我的测试肯定有两个标签。

    【讨论】:

    • 从行为 --tags-help (作为接受的答案)中读取“和”使用“行为 -t 一 -t 二”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多