pytest+allure生成报告显示loading和404

pytest+allure执行测试脚本后,通常会在电脑的磁盘上建立一个临时文件夹,里面存放allure测试报告,但是这个测试报告index.html文件单独去打开,却显示loading和404, 这个时候就要用一些办法来解决这个报告显示的问题了。

用命令产生的测试报告存放在临时文件夹

**原因:**allure生成的html测试报告,无法直接双击在浏览器中显示,需要用allure命令,执行后自动打开浏览器显示。

解决办法: allure提供了两种解决办法,allure serve和allure open两个命令。

1.allure serve: 当已经在之前用pytest -n auto --alluredir=allure执行完用例脚本后,用allure serve allure命令产生过allure报告后,单独打开index.html就会如上图显示loading, 404

用pytest -n auto --alluredir=allure产生的测试报告数据如下,将数据直接转换成html并自动打开,放置测试报告数据的文件夹allure下数据如下:

在allure上级目录下执行allure serve allure 即可打开测试报告。

这个命令产生的报告都是存放在临时文件夹下。

命令执行后自动打开浏览器,显示测试报告。

  1. allure open: 此命令适用于已经生成了index.html文件

在其上级路径下执行allure open allure-report即可自动打开测试报告:

这样自动打开测试报告

到了这里问题就基本解决了,但是每次都手动打命令有点麻烦,我们还可以把它改造成用bat批处理文件的方式来打开。

python 复制代码
if __name__ == '__main__':

    os.system('pytest -vs test_yesapi_1.py --alluredir ./allure')

    # 测试报告路径
    report_path = os.path.join(os.path.dirname(__file__, 'allure')
    
    bat_file_path = os.path.join(os.path.dirname(__file__, 'click.bat')
    
    if os.listdir(report_path):
        with open(bat_file_path, 'w') as f:
            f.write('allure serve allure')

这样就完美地解决了问题,双击打开bat文件就能打开测试报告了。

相关推荐
明月与玄武11 小时前
Pytest多环境切换实战:测试框架配置的最佳实践!
pytest·pytest框架环境切换
<花开花落>9 天前
将Python第三方库转换为真正的 pytest 插件
pytest
春风又。12 天前
接口自动化——初识pytest
python·测试工具·自动化·pytest
南部余额12 天前
playwright解决重复登录问题,通过pytest夹具自动读取storage_state用户状态信息
前端·爬虫·python·ui·pytest·pylawright
小码哥说测试15 天前
接口自动化进阶 —— Pytest全局配置pytest.ini文件详解!
自动化测试·软件测试·测试工具·自动化·pytest·测试工程师
天才测试猿16 天前
Python常用自动化测试框架—Pytest
自动化测试·软件测试·python·功能测试·测试工具·测试用例·pytest
Rhys..16 天前
2、pytest核心功能(进阶用法)
开发语言·python·pytest
一只天蝎的晋升之路17 天前
Python中常用的测试框架-pytest和unittest
开发语言·python·pytest
明月与玄武17 天前
pytest-xdist 进行高效并行自动化测试
pytest·pytest-xdist·进行高效并行自动化测试