# 运行并输出报告在Report文件夹下
查看生成的allure报告
1. 生成allure报告:pycharm terminal中输入命令:产生报告文件夹
pytest -s --alluredir=../report 
2. pycharm terminal中输入命令:查看生成的allure报告
allure serve ../report 
跳转至该页面,其中192.168.0.29为我的IP Address.

--------------------------------------------------------------------------------------
生成测试报告进化。。。
像上面的查看测试报告,比较麻烦,我们可以多做一步,使查看报告简便一些, PycharmTerminal中输入命令
|   1  |   
  | 
这里我输入命令:
allure generate ../report -o ../report/html --clean
 
allure generate ./temp -o ./report --clean
 
allure generate :命令语法
 ./temp:找到json的临时报告
 -o ./report:在report目录下生成allure报告
 –clean:每次运行都删除点之前的

在report/html下产生了对应的html报告文件
这样打开的测试报告跟第一种查看的测试报告数据是一样的,打开的时候就不需要在每次在dos窗口下输入命令了,但是这种的在PyCharm中可以直接浏览器打开,如果说你发给别人看的时候,就不能直接用浏览器打开了,需要开启一个web服务,如下
|   1  |   
  | 
执行完后,浏览器就会自动打开 http://192.168.0.29:51554/index.html查看报告
另外:cls清除黑窗口中的内容
Allure + pytest 自动生成测试报告:
代码示例如下:
# coding=utf-8
import pytest
import allure
import os
 
@pytest.fixture(scope='function')
def login():
    print("登录")
    yield
    print("登录完成")
 
@allure.feature('加入购物车')
def test_1(login):
    '''将苹果加入购物车'''
    print("测试用例1")
 
@allure.feature('加入购物车')
def test_2():
    '''将橘子加入购物车'''
    print("测试用例2")
 
if __name__ =="__main__":
    # 执行pytest单元测试,生成 Allure 报告需要的数据存在 /temp 目录
    pytest.main(['--alluredir', './temp'])
    # 执行命令 allure generate ./temp -o ./report --clean ,生成测试报告
    os.system('allure generate ./temp -o ./report --clean') 
运行后:












![[图解]分析模式高阶+课程讲解03物品模式](https://img-blog.csdnimg.cn/direct/b0960148e0c8448c91ca5265137ae2df.png)


![[Cloud Networking] OSPF](https://img-blog.csdnimg.cn/direct/70fbaafc6078451cb23ec9e98b596777.png)



