pytest+allure 生成图文并茂的测试报告

pytest+allure 生成图文并茂的测试报告

参考链接

pytest 官网:https://docs.pytest.org/en/stable/
allure :http://allure.qatools.ru/

pytest 安装

pip install pytest -U or
pip3 install pytest -U

pytest 常用的参数

-v 打印详细日志
-s 打印 print 输出的信息
--lf 只运行上一次失败的用例

pytest 用例识别规则 (背下来)

  • 测试文件
    • test_.py(星代表 任何字符)
    • *_test.py
  • 用例识别
    • Test*类包含的所有test_*的方法(测试类不能带有__init__方法)
    • 不在class中的所有的test_*方法
  • pytest也可以执行unittest框架写的用例和方法

pycharm 配置

pytest 框架结构

  • import pytest 类似的setup,teardown同样更灵活,
    • 模块级(setup_module/teardown_module)模块始末,全局的(优先最高
    • 函数级(setup_function/teardown_function)只对函数用例生效(不在类中)
    • 类级(setup_class/teardown_class)只在类中前后运行一次(在类中)
    • 方法级(setup_method/teardown_methond)开始于方法始末(在类中)
    • 类里面的(setup/teardown)运行在调用方法的前后

allure 安装

1、安装 allure工具(信赖java 环境,java1.8版本)
https://mvnrepository.com/artifact/io.qameta.allure/allure-commandline
下载 allure最新的版本,配置 bin/ 目录到 path里

2、安装 allure-pytest 插件
pip install allure-pytest

allure 命令行参数

pytest --alluredir ./result (生成中间文件)
allure serve ./result (生成在线版本的测试报告)
allure generate ./result (生成最终的html报告)