Pytest测试用例执行顺序及生成测试报告

205 阅读1分钟

order控制

首先安装pytest_ordering pip install pytest_ordering
使用装饰器

@pytest.mark.run(order=n)  #会按照n的数字大小顺序执行

按模块执行

在pytest.ini里添加markers

image.png

再用例上添加装饰器

image.png

执行用例时附带上参数 -m marker

image.png

跳过用例

用例前添加

@pytest.mark.skip(reason="跳过原因")

image.png

按条件跳过

添加装饰器 第一个参数为boolean值

@pytest.mark.skipif(a==1,reason='跳过原因')

image.png

生成报告

安装pytest-html
pip install pytest-html

在根目录下创建新文件夹 report

添加 参数 --html ./report/report.html

image.png

用例执行后在目标文件夹中生成测试报告

image.png