• 跳过用例skip


    1、装饰器,放在函数前面,跳过用例 @pytest.mark.skip(reason="no way of currently testing this")

    import pytest
    
    def test1():
        print('操作1')
        print("-----------------------------------------------")
    
    @pytest.mark.skip(reason="no way of currently testing this")
    def test12():
        print('操作2')
        print("-----------------------------------------------")
    
    
    def test3():
        print('操作3')
    
        print("-----------------------------------------------")
    
    
    if __name__ == '__main__':
        pytest.main(['-s', "text.fix2.py"])

    2、放在函数里面,只控制某条用例

    import pytest
    
    
    def test_123():
        pytest.skip("Not implemented")
        assert 1 == 0
    
    
    def test_234():
        assert 1 == 1

    3、跳过某个模块

    @pytest.importskip("模块名")

    4、根据版本去控制跳过某个模块

    @pytest.importskip("模块名",minversion="version_num")

    5、如果您希望有条件地跳过某些内容,则可以使用skipif代替

    import sys
    @pytest.mark.skipif(sys.version_info < (3,6),
    reason="requires python3.6 or higher")
    def test_function():
        ...

    如果条件在收集期间评估为True,则将跳过测试函数,具有指定的原因使用-rs时出现在摘要中。

    您可以在模块之间共享skipif标记。参考以下案例

    # content of test_mymodule.py
    import mymodule
    minversion = pytest.mark.skipif(mymodule.__versioninfo__ < (1,1),
    reason="at least mymodule-1.1 required")
    @minversion
    def test_function():
        ...

    您可以导入标记并在另一个测试模块中重复使用它:

    # test_myothermodule.py
    from test_mymodule import minversion
    @minversion
    def test_anotherfunction():
        ...

    对于较大的测试套件,通常最好有一个文件来定义标记,然后一致适用于整个测试套件。

    或者,您可以使用条件字符串而不是布尔值,但它们之间不能轻易共享它们支持它们主要是出于向后兼容的原因

    6、skip类或模块

    @pytest.mark.skipif(sys.platform == 'win32',
    reason="does not run on windows")
    class TestPosixCalls(object):
        def test_function(self):
            "will not be setup or run under 'win32' platform"

    警告:强烈建议不要在使用继承的类上使用skipif。 pytest中的一个已知错误标记可能会导致超类中的意外行为。

  • 相关阅读:
    atitit.颜色查找 根据范围 图像处理 inRange
    Atitit 跨平台的系统截图解决方案
    Atitit java opencv 捕获视频
    路法Atiti
    Atitit 获取本机图像设备视频设备列表 设备检索列表解决方案
    Atitit 团队工具链体系打造提升团队效率的一些通用软件 attilax总结
    Atitit gui控件定位解决方案
    Atitit html5.1 新特性attilax总结
    Atitti 模板匹配 List matchTemplate(
    利用CRebar和CDialogBar编写可浮动的dialog类型的工具栏
  • 原文地址:https://www.cnblogs.com/guo2733/p/10536060.html
Copyright © 2020-2023  润新知