pytest + allure 生成自定义报告
windows下安装 Allure工具
环境
1、安装JDK1.8+
2、安装Allure
- 下载Allure的zip安装包,
- 解压到allure-commandline目录
- 进入bin目录,运行allure.bat
- 添加allure到环境变量PATH(\安装路径\allure-commandline\bin)
用到的第三方包,及安装命令:
pip install pytest
pip install allure-pytest
import pytest
import allure
@allure.feature('测试demo')
@allure.story('测试项目')
@allure.description('项目描述')
@allure.title('用例标题')
def test_case_1():
with allure.step('测试用例步骤'):
assert 1==1
def test_case_2():
assert 1 +1 ==2
@allure.title('用例标题')
def test_case_3():
assert 1+2 ==12
# test_case_1()
# test_case_2()
# test_case_3()
if __name__ == "__main__":
pytest.main(['-s','./test_com.py','--alluredir','temp'])
temp生成后,在TM或者Cmd你代码目录下执行此命令
allure generate ./temp -o ./report --clean
也可以在脚本中执行os.system(allure generate ./temp -o ./report --clean)
在同级目录下生成report文件,打开index.html,用谷歌浏览器打开就可以看到报告
如果报告没有更新,删除temp和report文件,重新脚本和命令,
注意:本地打开index,会不显示报告,必须发布或者需要执行完程序,才可以执行,
参考文章:
https://blog.csdn.net/chenfei_5201213/article/details/80982929