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")