【使用pytest重构项目】pytest allure生成测试报告
2023-09-11 14:17:00 时间
前言
一直想学习自动化测试,但是都没行动,业余时间学习零零碎碎并记录20210420。
6、使用pytest重构项目
- pytest框架介绍
- pytest标记
- pytest参数处理
- pytest Fixtrue
- pytest allure生成测试报告
- pytest setup和teardown应用
- 使用pytest重构项目
pytest allure生成测试报告
1、安装插件allure-pytest
- (Mac):pip3 install allure-pytest
- (Windos):pip install allure-pytest
ffdeMBP ~ % pip3 install allure-pytest
Defaulting to user installation because normal site-packages is not writeable
Collecting allure-pytest
Downloading allure_pytest-2.8.40-py3-none-any.whl (9.6 kB)
Requirement already satisfied: six>=1.9.0 in /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/site-packages (from allure-pytest) (1.12.0)
Requirement already satisfied: pytest>=4.5.0 in /Library/Python/3.7/site-packages (from allure-pytest) (6.2.3)
Collecting allure-python-commons==2.8.40
Downloading allure_python_commons-2.8.40-py3-none-any.whl (15 kB)
Requirement already satisfied: attrs>=16.0.0 in /Library/Python/3.7/site-packages (from allure-python-commons==2.8.40->allure-pytest) (20.3.0)
Requirement already satisfied: pluggy>=0.4.0 in /Library/Python/3.7/site-packages (from allure-python-commons==2.8.40->allure-pytest) (0.13.1)
Requirement already satisfied: importlib-metadata>=0.12 in /Library/Python/3.7/site-packages (from pluggy>=0.4.0->allure-python-commons==2.8.40->allure-pytest) (3.10.1)
Requirement already satisfied: typing-extensions>=3.6.4 in /Library/Python/3.7/site-packages (from importlib-metadata>=0.12->pluggy>=0.4.0->allure-python-commons==2.8.40->allure-pytest) (3.7.4.3)
Requirement already satisfied: zipp>=0.5 in /Library/Python/3.7/site-packages (from importlib-metadata>=0.12->pluggy>=0.4.0->allure-python-commons==2.8.40->allure-pytest) (3.4.1)
Requirement already satisfied: py>=1.8.2 in /Library/Python/3.7/site-packages (from pytest>=4.5.0->allure-pytest) (1.10.0)
Requirement already satisfied: toml in /Library/Python/3.7/site-packages (from pytest>=4.5.0->allure-pytest) (0.10.2)
Requirement already satisfied: packaging in /Library/Python/3.7/site-packages (from pytest>=4.5.0->allure-pytest) (20.9)
Requirement already satisfied: iniconfig in /Library/Python/3.7/site-packages (from pytest>=4.5.0->allure-pytest) (1.1.1)
Requirement already satisfied: pyparsing>=2.0.2 in /Library/Python/3.7/site-packages (from packaging->pytest>=4.5.0->allure-pytest) (2.4.7)
Installing collected packages: allure-python-commons, allure-pytest
Successfully installed allure-pytest-2.8.40 allure-python-commons-2.8.40
2、下载allure一个可执行文件
- 地址:https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.7.0/
- 设置环境变量:.bash_profile文件增加(PATH=$PATH:/usr/local/allure-2.7.0/bin)
~ % cd Downloads
Downloads % sudo mv allure-2.7.0 /usr/local
Password:
% cd /usr/local
% ls
Caskroom Frameworks allure-2.7.0 etc lib sbin solarized
Cellar Homebrew bin include opt share var
local % cd allure-2.7.0/bin
bin % pwd
/usr/local/allure-2.7.0/bin
bin % cd ~
~ % vim .bash_profile
~ % source .bash_profile
~ % allure --version
2.7.0
allure用例描述
使用方法 | 参数值 | 参数说明 |
---|---|---|
@allure.epic() | epic描述 | 敏捷里面的概念,定义史诗,往下是feature |
@allure.feature() | 模块名称 | 功能点的描述,往下是story |
@allure.story() | 用户故事 | 用户故事,往下是title |
@allure.title(用例的标题) | 用例的标题 | 重命名html报告名称 |
@allure.testcase() | 测试用例的链接地址 | 对应功能测试用例系统里面的case |
@allure.issue() | 缺陷 | 对应缺陷管理系统里面的链接 |
@allure.description() | 用例描述 | 测试用例的描述 |
@allure.step() | 操作步骤 | 测试用例的步骤 |
@allure.severity() | 用例等级 | blocker,critical,normal,minor,trivial |
@allure.link() | 链接 | 定义一个链接,在测试报告展现 |
@allure.attachment() | 附件 | 报告添加附件 |
测试案例
-
pytest结合allure测试用例
#pytest生成测试报告
import allure
import pytest
@pytest.fixture(scope="session")
def login():
print("用例先登录")
@allure.step("步骤1:点xxx")
def step_1():
print("111")
@allure.step("步骤2:点xxx")
def step_2():
print("222")
@allure.feature("编辑页面")
class TestEditPage():
"""编辑页面"""
@allure.story("这是一个xxx的用例")
def test1(self,login):
"""用例描述 先登录再执行story的用例"""
step_1()
step_2()
print("这是一个xxx的用例")
@allure.story("打开a页面")
def test2(self,login):
"""用例描述:先执行fixcure的登录然后再执行yyy"""
print("yyy")
if __name__ == '__main__':
# 注意生成测试报告必须在命令行执行
# 所以执行时要切换到seelenium_projrct目录下去
# pytest --alluredir ./reports testcases/pytest/test_07.py # 生成测试报告存放到路径reports目录下
# 所以执行时要切换到seelenium_projrct目录下去
# allure serve ./reports 启动allure 查看报告
pytest.main(['--alluredir' './reports' 'test_07.py'])
-
查看报告(打开终端,切换到seelenium_projrct目录下去,用 allure serve ./reports命令启动allure 查看报告)
“永不放弃,总有希望在前面等待!”送给自己,也送给正在阅读文章的博友们~
相关文章
- pytest + allure + jenkins 生成漂亮的测试报告
- pytest接口自动化测试框架 | 接口测试概述
- Python+Pytest+Allure+Git+Jenkins接口自动化框架
- Pytest自动化测试使用pytest.ini实现环境变量控制
- Pytest自动化测试教程22-优质集成实践
- 九、Pytest框架 — Pytest框架的setUp()和tearDown()函数
- 四、Pytest框架 — pytest.ini文件和用例执行的顺序以及跳过测试和失败重试
- 【2023最新最火教程】Pytest 自动化测试框架 (超详细~)
- 测试开发实战项目 | 搭建Pytest接口自动化框架
- 2022全网最全教程,一篇文章带你学会 Pytest 测试框架
- [转]Python测试框架对比----unittest, pytest, nose, robot framework对比
- Pytest----如何通过marker向fixture传值
- Pytest----如何重复执行脚本即pytest-repeat插件的使用方法
- Pytest----如何执行未安装的本地包中的测试脚本
- pytest控制用例执行顺序
- Pytest测试框架基本使用方法详解