【发布时间】: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