一、前言
在之前我们有提到过使用pytest-html插件可以帮助我们生成漂亮的报告,那么有没有更好的解决方案呢,allure报告目前来说是现在是业界最好的一种方案,并且支持多语言多种单元测试框架,现在我们来演示是如何支持pytest。
二、事前准备
1、安装插件allure-pytest
pip install allure-pytest
2、下载安装jdk1.8,并配置环境变量
3、下载安装allure-commandline,并配置环境变量
2和3可自定网上搜索,这里不必再细说
三、演示步骤
1、代码
#!/usr/bin/python3 # -*- coding: UTF-8 -*- """ @author:durant.zeng @Description:描述 @file:test_rerun.py @time:2020/12/11 """ import requests def test_taobao1(): url = "https://taobao.com" r = requests.post(url=url,timeout=0.30) print(r.elapsed.total_seconds()) def test_taobao2(): url = "https://taobao.com" r = requests.post(url=url,timeout=0.30) print(r.elapsed.total_seconds()) def test_taobao3(): url = "https://taobao.com" r = requests.post(url=url,timeout=0.09) print(r.elapsed.total_seconds())
2、生成allure报告文件
pytest --reruns 2 --alluredir=./allure_result
--alluredir:指定报告的路径
./allure_result:具体的路径
output:
(CloudStorage) D:learnIOTCloudStorageunit>pytest --reruns 2 --alluredir=./allure_result Test session starts (platform: win32, Python 3.7.2, pytest 6.0.1, pytest-sugar 0.9.4) rootdir: D:learnIOTCloudStorageunit plugins: Faker-4.1.3, html-3.1.0, metadata-1.11.0, rerunfailures-9.1.1, sugar-0.9.4, tavern-1.11.1, allure-pytest-2.8.18, base-url-1.4.2, forked-1.3.0, xdis t-2.1.0 collecting ... test_rerun.py R✓ 33% ███▍ test_rerun.py R✓✓ 67% ████ test_rerun.py R✓✓R✓ 100% ███ ███████ ==================================================================== warnings summary ===================================================================== c:usersdurant.zeng.virtualenvscloudstoragelibsite-packagespykwalifycore.py:7 c:usersdurant.zeng.virtualenvscloudstoragelibsite-packagespykwalifycore.py:7: DeprecationWarning: the imp module is deprecated in favour of import lib; see the module's documentation for alternative uses import imp -- Docs: https://docs.pytest.org/en/stable/warnings.html Results (3.20s): 3 passed 2 rerun
生成的是一些json和txt文件,还不是直观的测试报告
3、生成真正的可视化漂亮报告
allure serve ./allure_result
自动的打开网页,展示报告
至此,一个漂亮的allure报告就出现了,后面更多的功能还需细细探索~