Brief introduction
Before the macro brother doing when automation interfaces, test report using a HTMLTestRunner, although the custom template to meet the basic demands, but still was not very grade, high-end, the atmosphere, then want to replace it with another excellent report framework. By chance, I saw a QQ group test report Allure, really love at first sight, especially like. However, due to the time it would not have their own practice, riding on the National Day holiday, their own special time to do some exploring.
Allure introduction
Allure is a flexible lightweight multi-language test reporting tools, which not only can be very concisely displays the contents of the tested Web report concise form, but also allows everyone involved in the development process of extracting the maximum extent from the daily execution useful information.
From development / quality assurance perspective, Allure report can shorten the life cycle of common defects: test failure can be divided into bug and broken test, you can also configure the log, steps, fixtures, accessories, time, history, and with TMS integration and Bug tracking system, responsible developers and testers will have all the information.
From the perspective of the manager's point of view, Allure provides a clear "global", covers the functions covered by the defect collection location, appearance timetable for implementation, and many other convenient thing. The modular and scalable charm ensure that you can always fine-tune some things, so that charm is right for you.
See the Allure style
Before the commencement of Allure detail, the first on a test report, the report contains seven most major overview, categories, test kits, charts, time scale, function, package, and support for many custom information, including attachments added, defect link case links, test procedures, Epic, Feature, Story, Title, case level, etc., is quite powerful.
Want to learn more about Allure partners and small children's shoes, you can visit this Web site: https://demo.qameta.io/allure
Overview
category
Test Suite
chart
Timescale
Features
1. pytest installation :( here focuses on Windows)
pytest
是python
的一个第三方单元测试框架,在这里用于生成原始的执行结果。
一定别选最新的,4.0.2亲测可用,否则会跳到坑二;还有项目名千万别以pytest开头
1.1. windows下:
pip install pytest
出现如下图所示,pytest安装成功
1.2. linux下:
pip install pytest
2. 安装pytest-allure-adaptor插件
据了解,安装pytest-allure-adaptor
。这个第三方库已经过时了,无法和现有的pytest
搭配使用。宏哥这个先安装后期遇到问题再去处理。
最新的安装需要下面这个:
allure-pytest是python的一个第三方库。用于连接pytest和allure,使它们可以配合在一起使用。
allure-pytest基于pytest的原始执行结果生成适用于allure的json格式结果。该json格式结果可以用于后续适用allure生成html结果。
2.1. windows下:
pip install pytest-allure-adaptor
出现如下图所示,pytest-allure-adaptor安装成功
3. allure的安装:
3.1. windows下:
前情提示: allure
是基于Java
的一个程序,需要Java1.8+
的环境,没有安装需要去安装一下。
或者到这个网址:https://github.com/allure-framework/allure2/releases/ 、https://bintray.com/qameta/generic/allure2下载你需要的版本的安装包
下载之后,将压缩包解压到一个磁盘中,我这里用的是D盘
3.2. 配置allure
的环境变量
将此路径:D:\software\allure-2.13.0\bin,用老办法配置到path中
点击确定,保存。这样就可以通过CMD
使用allure
命令
3.3. 编写测试文件
pycharm
新建一个test_demo.py
文件,代码如下:
import allure @allure.MASTER_HELPER.feature("测试Dome") class TestDome(object): @allure.MASTER_HELPER.step("定义被测函数") def func(self, x): return x+1 @allure.MASTER_HELPER.story("被测场景") @allure.MASTER_HELPER.severity("blocker") @allure.MASTER_HELPER.step("断言结果") def test_func(self): # with allure.MASTER_HELPER.step("断言结果"): allure.MASTER_HELPER.attach("预期结果", "{}".format(self.func(3))) allure.MASTER_HELPER.attach("实际结果", "{}".format(5)) assert self.func(3) == 5
3.4. 生成测试报告
在pycharm
中打开terminal
输入命令pytest -s --alluredir=report
运行后,无上述错误,同时会生成一个report
文件。其中会有一个json
格式的报告:
回到根目录下,会生成一个allure-report
的文件夹,在pycharm
中打开文件夹,点击index.html
运行
ok,到此为止。可以看到我们的精美的测试报告了
1.安装pytest-allure-adaptor后,运行报错:AttributeError: module 'pytest' has no attribute 'allure'
原因:因为pytest-allure-adaptor库基本被python3放弃了,运行很不友好,反正我运行就是报错
解决方法:
先卸载:pip uninstall pytest-allure-adaptor
再安装:pip install allure-pytest
然后再去对应case的文件夹下面cmd里面运行: pytest -s -q --alluredir report (可以改为你想设的路径,如果是report默认当前目录下),就会生成report文件夹了
2.输入命令pytest -s --alluredir=report
,会遇到以下这个错误:
进入allure
下面的utils
文件,修改以下代码:
# utils文件,可以通过from allure import utlis进入
for suitable_name in suitable_names:
# markers.append(item.get_marker(suitable_name))
markers.append(item.get_closest_marker(suitable_name))
您的肯定就是我进步的动力。如果你感觉还不错,就请鼓励一下吧!记得点波 推荐 哦!!!(点击右边的小球即可!(^__^) 嘻嘻……)