详细内容可以参考官方文档:https://docs.qameta.io/allure-report/;
Allure
是一个多语言测试报告工具;Web
形式显示报告内容;重点:拓展功能需要在测试用例集上加装饰器。(后续文章再学习)
pip3 install allure-pytest
C:\Users\Administrator>pip3 install allure-pytest
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: allure-pytest in d:\python37\lib\site-packages (2.8.12)
Requirement already satisfied: six>=1.9.0 in d:\python37\lib\site-packages (from allure-pytest) (1.15.0)
Requirement already satisfied: allure-python-commons==2.8.12 in d:\python37\lib\site-packages (from allure-pytest) (2.8.12)
Requirement already satisfied: pytest>=4.5.0 in d:\python37\lib\site-packages (from allure-pytest) (6.2.4)
Requirement already satisfied: attrs>=16.0.0 in d:\python37\lib\site-packages (from allure-python-commons==2.8.12->allure-pytest) (20.3.0)
Requirement already satisfied: pluggy>=0.4.0 in d:\python37\lib\site-packages (from allure-python-commons==2.8.12->allure-pytest) (0.13.1)
Requirement already satisfied: importlib-metadata>=0.12 in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (2.1.1)
Requirement already satisfied: iniconfig in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (1.1.1)
Requirement already satisfied: py>=1.8.2 in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (1.10.0)
Requirement already satisfied: packaging in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (20.8)
Requirement already satisfied: colorama in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (0.4.4)
Requirement already satisfied: atomicwrites>=1.0 in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (1.4.0)
Requirement already satisfied: toml in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (0.10.2)
Requirement already satisfied: zipp>=0.5 in d:\python37\lib\site-packages (from importlib-metadata>=0.12->pytest>=4.5.0->allure-pytest) (1.2.0)
Requirement already satisfied: pyparsing>=2.0.2 in d:\python37\lib\site-packages (from packaging->pytest>=4.5.0->allure-pytest) (2.4.7)
pip3 install pytest
Windows
操作系统,所以下载zip
文件:
allure --version
C:\Users\Administrator>allure --version
2.13.2
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/20
# 文件名称:test_xxx.py
# 作用:示例
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import pytest
import time
class TestCase01():
def test_case_01(self):
time.sleep(1)
print("case01$$$$$$$$$$$$$$$$$$$$$")
def test_case_02(self):
time.sleep(1)
print("case02$$$$$$$$$$$$$$$$$$$$$")
def test_case_03(self):
time.sleep(1)
print("case03$$$$$$$$$$$$$$$$$$$$$")
def test_case_04(self):
time.sleep(1)
print("case04$$$$$$$$$$$$$$$$$$$$$")
def test_case_05(self):
time.sleep(1)
print("case05$$$$$$$$$$$$$$$$$$$$$")
def test_case_06(self):
time.sleep(1)
print("case06$$$$$$$$$$$$$$$$$$$$$")
class TestCase02():
def test_case_07(self):
time.sleep(1)
print("case07$$$$$$$$$$$$$$$$$$$$$")
def test_case_08(self):
time.sleep(1)
print("case08$$$$$$$$$$$$$$$$$$$$$")
def test_case_09(self):
time.sleep(1)
print("case08$$$$$$$$$$$$$$$$$$$$$")
if __name__ == '__main__':
pytest.main(["-s", "test_xxx.py"])
pytest -n auto --alluredir=xxx/xxx/xxx
来运行查看测试结果,其中--alluredir
是指定报告存放的路径,比如:pytest -n auto --alluredir=allure
test_xxx.py
,报告存放路径在当前脚本的路径:pytest -n auto --alluredir=allure test_xxx.py
gw0 [9] / gw1 [9] / gw2 [9] / gw3 [9] / gw4 [9] / gw5 [9] / gw6 [9] / gw7 [9]
......... [100%]
============================================= 9 passed in 4.66s ==============================================
test_xxx.py
的相同路径下,生成一个allure
的文件夹:allure
命令来显示测试报告:allure serve allure
(venv) F:\pytest_study\test_case\test_j>allure serve allure
Generating report to temp directory...
Report successfully generated to C:\Users\ADMINI~1\AppData\Local\Temp\743714976960418009\allure-report
Starting web server...
2023-03-20 11:16:28.270:INFO::main: Logging initialized @4392ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://172.16.1.33:13959/>. Press <Ctrl+C> to exit
allure serve -p 8888 allure
字段 | 说明 |
---|---|
| 报告总览 |
| 类别,查看用例执行情况比如 |
| 测试套件,根据 |
| 测试结果图形 ,有分布图,优先级,耗时等 |
| 用例运行时间等 |
| 行为驱动, 根据 |
| 按照 |