标签(烟雾/回归)从 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。 …