zoukankan      html  css  js  c++  java
  • 跳过用例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中的一个已知错误标记可能会导致超类中的意外行为。

  • 相关阅读:
    Winform中怎样设置ContextMenuStrip右键菜单的选项ToolStripMenuItem添加照片
    JavaScript垃圾回收机制
    前端如何处理内存泄漏
    前端缓存
    深入理解vue-router之keep-alive
    (淘宝无限适配)手机端rem布局详解
    mysql不会使用索引,导致全表扫描情况
    MYSQL性能优化的最佳20+条经验
    深拷贝与浅拷贝的区别,实现深拷贝的几种方法
    vue组件通信方式总结
  • 原文地址:https://www.cnblogs.com/guo2733/p/10536060.html
Copyright © 2011-2022 走看看