栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pytest使用介绍

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pytest使用介绍

1、常用插件
pytest-html 生成html报告的插件
pytest-xdist 多线程允许的插件
pytest-ordering 改变用例的执行顺序的插件
pytest-rerunfailures 失败用例重跑的插件
allure-pytest 生成美观自定`在这里插入代码片`义的allure报告
2、默认规则
  • 模块名必须test_开头或者_test结尾
  • 测试类必须以Test开头,并且不能带有init方法
  • 测试用例必须以test_开头
  • 可以命令行执行,也可以主函数调用执行
  • 执行的参数:
    -v输出详细信息 -s输出调试信息
    -n多线程执行(前提安装pytest-xdist,命令如下:pytest -vs -n=2)
    -reruns=num 失败重跑(前提安装pytest-rerunfailres)
    -x 出现一个用例失败就停止测试
    –maxfail=num 出现几个失败才终止
    –html 生成html测试报告(前提安装pytest-html)
    -k “name” 运行测试用例名称中包含某个字符串的测试用例
import  pytest
def test_b():
    print("bbbb")
class Test_a:
    def test_default_health(self):
        print("aaa")
        raise Exception("lalallalalal")
if __name__=="__main__":
    pytest.main(['-vsreruns=2'])
    pytest.main(['--html=re.html'])
3 pytes跳过测试用例
	@pytest.mark.skip(reason="无理由我就是想跳过")
    def test_a(self):
        print("cccc")
    @pytest.mark.skipif(age<11,reason="age<11跳过")
    def test_bb(self):
        print("hfc")
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/942645.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号