pytest框架

一、介绍
pytest是python的第三方单元测试框架,比自带unittest更简洁和高效
支持315种以上的插件,同时兼容unittest框架
在unittest框架迁移到pytest框架的时候不需要重写代码

二、环境搭建
首先使用pip安装pytest

pip install pytest  # 使用国内镜像站
pip install pytest-html # 原生态报告模板

查看pytest是否安装成功

pip show pytest  # 使用国内镜像站

注意点:
1、py测试文件必须以test_开头(或者以_test结尾)
2、测试类必须以Test开头,并且不能有__init__方法
3、测试方法必须以test_开头
4、断言必须使用assert

三、框架使用
1、执行顺序:@pytest.fixture(scope='')
scope='function' 默认级别,每个方法或函数都跑一次
scope='class' 每个类执行一次
scope='module' 每个模块执行一次
scope=

你可能感兴趣的:(持续集成,pytest)