如何在 pytest 中将多个标签应用于测试用例?

Wla*_*lad 5 tags tagging markers pytest

pytest中,您可以使用标签来标记测试用例。

@pytest.mark.windows
def test_will_fail():
    assert False
Run Code Online (Sandbox Code Playgroud)

现在上面的测试用例标有标签“windows”。运行 pytestpytest -m windows将仅执行标有“windows”标签的测试用例。

但如果我想应用多个标签怎么办?例如,我想用“windows”和“smoke”标记上面的测试用例。我该怎么做呢?(我在 pytest 文档中没有看到相关示例。)

The*_*ler 6

这些只是可以堆叠的Python 装饰器:

@pytest.mark.smoke
@pytest.mark.windows
def test_will_fail():
    assert False
Run Code Online (Sandbox Code Playgroud)