运行pytest用例不生成allure报告

1.安装allure

  1.   下载allure的zip安装包
  2. 将allure.zip解压到python的lib目录中
  3. 将allure的bin路径添加到环境变量path中(注意:配置环境变量后,一定要重启电脑。因为环境变量没生效,我搞了半天在pycharm不能生成报告,在cmd中可以生成报告)
  4. 安装allure-pytest,命令为:  pip install allure-pytest

2.验证是否安装成功

  方法一:在cmd中输入 allure -v

 

  方法二:在pycharm中输入 allure(输入环境变量没有生效,这里是不会有信息的)

 

 

 3.踩坑一:在pycharm中,pytest程序运行成功,没有生成allure报告,运行结果如下图

 

 出现这个原因是环境变量没有生效,重启电脑后可以生成报告。

打开项目所在路径,在命令行输入命令可以生成allure报告

命令1(运行程序,生成报告):pytest test_food.py --alluredir ../report/tmp

pytest py文件名  --alluredir 生成报告文件的临时目录

命令2(启动服务,查看报告临时文件):allure serve ../report/tmp

allure serve  生成报告文件的临时目录

 

 

 

 

 踩坑二:pycharm运行,生成的allure报告没有数据

 

 原因:生成报告的源文件目录写错了

	pytest.main(['test_food.py','-s','--alluredir','../report/tmp'])
	os.system('allure generate ../report/tmp -o ../report/html --clean')#../report/tmp 为存放报告的源文件目录

  

 

4.allure生成报告的几种命令

1、生成测试报告数据
pytest test_food.py --alluredir ../report/tmp

2、测试报告在线预览

allure serve  ../report/tmp

3、测试报告本地静态数据生成

allure generate ../report/tmp -o ../report/html --clean

 

posted on 2020-11-17 10:03  小金鱼的笔记  阅读(6231)  评论(0编辑  收藏  举报