zoukankan      html  css  js  c++  java
  • pytest框架运用

    import pytest
    '''
    运行方式
    1. pytest -s test01.py  把print信息打印出来运行用例
    2. 通过main运行
    
    前置后置方法
    1. 函数级 setup teardown
    2. 类级别 setup_class teardown_class
    
    插件
    1. 生成测试报告
    下载:pip install pytest-html
    运行:pytest -s test01.py --html=report/report.html
    2. 控制用例执行顺序
    下载:pip install pytest-ordering
    通过装饰器 @pytest.mark.run(order=-2)
    规则:有正有负 正先执行
         同符号  越小优先级越高
    3. 用例错误重新运行
    下载:pip install pytest-rerunfailures
    运行:pytest -s test01.py --reruns 3  
    重新运行三次,如果还有问题报错
    ''' class TestStudy: def setup_class(self): print('-------->setup_class类级别做准备工作=======') def teardown_class(self): print('-------->teardown_class类级别做结束工作=====') #函数级别的setup和teardown def setup(self): print('-------->setup做准备工作') def teardown(self): print('-------->teardown做结束工作') @pytest.mark.run(order=-2) def test_01(self): print('---------->test01') assert 1 @pytest.mark.run(order=-11) def test_02(self): print('---------->test02') assert 0 if __name__ == '__main__': pytest.main(['-s','test01.py'])

    运行结果

    test01.py -------->setup_class类级别做准备工作=======
    -------->setup做准备工作
    ---------->test02
    -------->teardown做结束工作
    R-------->setup做准备工作
    ---------->test02
    -------->teardown做结束工作
    R-------->setup做准备工作
    ---------->test02
    -------->teardown做结束工作
    R-------->setup做准备工作
    ---------->test02
    -------->teardown做结束工作
    F-------->setup做准备工作
    ---------->test01
    -------->teardown做结束工作
    -------->teardown_class类级别做结束工作=====
    .
    
    ============================================================ FAILURES ============================================================
    _______________________________________________________ TestStudy.test_02 ________________________________________________________
    
    self = <test01.TestStudy object at 0x00000214164AF3A0>
    
        @pytest.mark.run(order=-11)
        def test_02(self):
            print('---------->test02')
    >       assert 0
    E       AssertionError
    
    test01.py:44: AssertionError
  • 相关阅读:
    浅谈px,em和rem这些单位的区别
    nodejs中的formidable模块
    es6中的Symbol.iterator属性
    jQuery源码解析----内部插入的外部函数
    关于js函数中存在异步的情况下的变量的分析
    jQuery源码解析----模拟核心buildFragment
    jQuery源码解析----模拟html()、text()、val()
    Config
    Zuul
    Hystrix
  • 原文地址:https://www.cnblogs.com/wangxue1314/p/13592191.html
Copyright © 2011-2022 走看看