pytest跳过指定的测试或模块

参考Allure官方文档pytest官方文档

实现setup/teardown

1.运行带指定标记的测试

@pytest.mark.tags ,这里的tags可以自定义

命令行执行:pytest -v -m 'tags' 

2.跳过指定的测试

@pytest.mark.skip(reason="过期")#跳过该测试
def test_app_logic():
    '''
    用例描述:逻辑测试
    '''
    print('逻辑测试')
    time.sleep(1)
    assert 1==1

3.跳过指定的模块

实际测试时,当 @pytest.importorskip("模块名",minversion="1.5")这个装饰器在哪个模块,哪个模块就会被跳过,模块名随便写都没影响。

@pytest.importorskip("test_ltcs",minversion="1.5")
@allure.step('检查UI名:{0}打开了')
def ui_check(tips):
    return tips

4.条件跳过指定的用例

@pytest.mark.skipif('2 + 2 != 5', reason='按条件触发')
def test_skip_by_triggered_condition():
    assert 2+2==4