小编Y52*_*288的帖子

将标签从 CLI 传递到 Pytest-bdd 并执行特定场景

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

我在这里查看了 pytest-bdd 文档 ,但未能找到连接。

场景大纲有:(因为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
Run Code Online (Sandbox Code Playgroud)

测试.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
Run Code Online (Sandbox Code Playgroud)

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

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

其中pytest_addoption用于--env='qa'pytest_bdd_apply_tagfor -m。 …

fixtures pytest python-3.x python-requests

4
推荐指数
1
解决办法
3903
查看次数

标签 统计

fixtures ×1

pytest ×1

python-3.x ×1

python-requests ×1