import pytest @pytest.mark.my_marker def test_example(): assert 1 + 1 == 2 pytest -m my_marker path/to/test_folder1 path/to/test_folder2 两个标记 对应两个分组如何去写

在pytest中,可以通过使用-m参数来运行指定标记的测试用例。如果有多个标记对应不同的分组,可以通过在函数上方使用@pytest.mark.<marker_name>来为测试用例添加标记。然后可以通过不同的标记来运行不同的分组测试用例。

下面是一个示例代码,演示如何为测试用例添加不同的标记:

import pytest

@pytest.mark.group1
def test_group1_example():
    assert 1 + 1 == 2

@pytest.mark.group2
def test_group2_example():
    assert 2 * 2 == 4

在上面的示例中,test_group1_example()函数被标记为group1test_group2_example()函数被标记为group2。接下来可以使用-m参数来运行不同的分组测试用例:

pytest -m group1 path/to/test_folder1

这样就可以只运行被标记为group1的测试用例。同样地,可以使用不同的标记来运行不同的分组测试用例。