【问题标题】:Pass tags from CLI to Pytest-bdd and execute specific scenarios将标签从 CLI 传递到 Pytest-bdd 并执行特定场景
【发布时间】:2019-06-06 20:53:12
【问题描述】:

要从 CLI 传递并在 conftest.py 中解释的标签(烟雾/回归)以执行满足标签的那些场景。

我查看了 pytest-bdd 文档 here 并没有找到连接。

Scenario Outline 有:(因为 python 装饰器可以堆叠)

@pytest.mark.smoke
Scenario Outline: "VALID" Test

@pytest.mark.smoke
@pytest.mark.regression
  Scenario Outline: "INVALID" Test

@pytest.mark.regression
  Scenario Outline: "MIXED" Test

conftest.py

def pytest_bdd_apply_tag(tag, function):    
    if 'smoke' not in tag:  #what should I use to take values from CLI and execute those
        marker = pytest.mark.skip # skips scenario where 'smoke' is not marked
        marker(function)
        return True
    return None

conftest.py 中的上述代码跳过了所有场景。 CLI 输入:

pytest --env='qa' -m 'smoke'

其中pytest_addoption 用于--env='qa',pytest_bdd_apply_tag 用于-m。

当我通过烟雾时,我们只想执行标记为烟雾(有效和无效)的场景;当我通过 -m 选项在 CLI 中不传递任何参数时,当我通过回归和默认烟雾时标记回归(无效和混合)的场景。

【问题讨论】:

    标签: python-3.x python-requests pytest fixtures


    【解决方案1】:

    我的错,我想知道我是如何被文档中提到的带有场景标签行的 pytest 标记误导的。

    我对功能文件所做的更改是

    @smoke
    Scenario Outline: "VALID" Test
    
    @smoke @regression
      Scenario Outline: "INVALID" Test
    
    @regression
      Scenario Outline: "MIXED" Test
    

    我已经从 conftest.py 中删除了 pytest_bdd_apply_tag 方法。

    在命令行中给出这个对我有用

    pytest -m "regression" --env="uat"
    

    【讨论】:

      猜你喜欢
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 2014-03-27
      • 1970-01-01
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      相关资源
      最近更新 更多