
pytest
文章平均质量分 58
奥斯卡的夫人
test
展开
-
pytest-简介
pytest框架特点入门简单,文档丰富支持简单的单元测试和复杂的功能测试支持参数化执行测试过程中可以将某些测试跳过,或者对某些预期失败的case标记成失败支持重复执行失败的case支持运行由unittest编写的测试case具有很多第三方插件,并且可以自定义扩展方便的和持续集成工具集成安装pip install -U pytest查看是否安装成功:pytest --version使用导入pytest:import pytest编写测试用例:无需在测试类下编写测试原创 2020-10-22 22:32:18 · 226 阅读 · 0 评论 -
pytest-fixture详解
fixture优势:pytest的fixture命名不在局限于setup和teardown命名方式所有的fixture都可以一个conftest.py的文件中,供所有测试用例使用fixture 创建和使用方法fixture 创建#1. @pytest.fixture()#2. 编写一个普通函数@pytest.fixture()def login(): print("执行登录")fixture 使用#在需要使用fixture的测试用例中,当做参数传入即可def test_sho原创 2020-10-22 22:25:48 · 2410 阅读 · 0 评论 -
pytest-预期失败
预期失败方法:xfail(condition=None,reason=None,raises=None,run=True,strict=False)常用参数:condition:预期失败的条件,必传 reason:失败的原因,必传使用方法:1.@pytest.mark.xfail(condition,reason=“xx”) 这个显示xfail,说明报错不符合预期2. 显示xpass -------> 说明报错符合预期一般不这么用,会使用pytest.raises先抛出接原创 2020-10-22 22:23:29 · 264 阅读 · 0 评论 -
pytest-参数化
参数化—一个参数语法:parametrize(argnames,argsvalues) –argnames:参数名–argvalues:参数值,数据类型list用法:@pytest.mark.parametrize(argnames,argvalues)示例:import pytest@pytest.mark.parametrize("mobile_phone",["11111111111","2222222222"])def test_register(mobile_phon原创 2020-10-22 22:20:44 · 159 阅读 · 0 评论 -
pytest-跳过某些用例执行
跳过测试方法:skipif(condition,reason=None)参数:condition,都是必传参数reason,必传参数语法:@pytest.mark.skipif(2>1,reason=“条件为真跳过测试”)原创 2020-10-22 22:16:18 · 740 阅读 · 0 评论 -
pytest-常用插件
常用插件插件一:pytest 测试报告安装库pip install pytest-html使用方法在配置文件添加参数addopts = -s --html = report/report.html直接在命令行使用:pytest -q test01.py --html=html/test01.html插件二:pytest 控制函数执行顺序安装库pip install pytest-ordering使用方法在被执行的用例前添加@pytest.mark.run(orde原创 2020-10-22 22:14:57 · 284 阅读 · 0 评论 -
pytest-配置文件
pytest 配置文件该操作就是为了省事,可以直接运行pytest不用加参数,类名等在主函数中执行pytest.main("-s 文件名称")命令行执行方式在测试用例所在目录下进入命令行输入pytest -s test_case_02.py在项目根目录下进入命令行pytest [参数] 执行文件在pycharm中,使用terminal选项代替命令行操作配置文件示例:pytest.ini(注意该文件 内不能有中文注释,实际运行时去掉中文)[pytest]#添加命原创 2020-10-22 22:13:24 · 187 阅读 · 0 评论 -
pytest-模块级别和函数级别的setup & teardown
模块级别和函数级别的setup & teardown在pytest 中setup 和 teardown 分为如下几种情况:模块级别 对整个.py文件作用setup_module/teardown_module函数级别 对测试用例作用(不在测试类中)setup_function/teardown_function类级别 对测试类作用setup_class/teardown_class方法级别 对测试类中的测试用例作用setup_method/teardown_m原创 2020-10-22 22:12:25 · 838 阅读 · 0 评论