Pytest学习笔记5——Allure测试报告用例详细描述
2023-06-13 09:16:49 时间
引言
如果做完自动化测试后,生成的结果可读性不强,那将会是一次失败的自动化测试。
pytest自动化测试中,要想报告内容丰富,优雅和可读性强,就需要与allure结合使用。
allure报告有很多特性,这些特性主要以装饰器、函数等的方式使用。
Allure装饰器描述
案例解析
在testcase新建conftest.py文件:
import pytest
@pytest.fixture()
def action():
print("测试开始".center(30,'*'))
yield
print("测试结束".center(30,'*'))
在测试文件testcase下新建测试文件test_qq.py文件:
import allure
from common import Log
import requests
@allure.step('这是测试步骤')
def step_1():
print("初始化数据")
@allure.epic('测试天气API接口'.center(30,'*'))
@allure.feature('测试模块')
@allure.suite('这是套件')
class TestHttpbin:
"""测试模块httpbin"""
def setup(self):
"""所有用例执行前的条件"""
self.logger = Log.MyLog()
@allure.severity('normal')
@allure.story('故事1:获取天气数据')
@allure.title('获取单个城市的天气')
@allure.description('获取深圳的天气')
@allure.testcase('测试用例地址:www.***.com')
@allure.issue('缺陷管理地址:https://www.zentao.net/')
@allure.tag('这是tag')
def test_001(self,action):
"""
测试httpbin接口:get方法
"""
step_1()
# api:host
url = 'https://tianqiapi.com/api'
params = {'version':'v6','appid':12253812,'appsecret':'KzT8yOpX'}
response = requests.get(url=url,params=params).json()
print('接口返回数据: %s'%response)
self.logger.info('接口返回数据: %s' % response)
报告生成
# 方法1
# 切换到testcase目录下
pytest -v test_qq.py --alluredir allure_report
allure serve allure_report
运行结果:
命令行参数
pytest运行用例的时候可以加上allure标记用例的参数
--allure-severities=SEVERITIES_SET
Comma-separated list of severity names. Tests only
with these severities will be run. Possible values
are: blocker, critical, normal, minor, trivial.
--allure-epics=EPICS_SET
Comma-separated list of epic names. Run tests that
have at least one of the specified feature labels.
--allure-features=FEATURES_SET
Comma-separated list of feature names. Run tests that
have at least one of the specified feature labels.
--allure-stories=STORIES_SET
Comma-separated list of story names. Run tests that
have at least one of the specified story labels.
--allure-link-pattern=LINK_TYPE:LINK_PATTERN
Url pattern for link type. Allows short links in test,
like 'issue-1'. Text will be formatted to full url
with python str.format().
# 选择运行你要执行epic的用例
pytest --alluredir ./report/allure --allure-epics=epic对大Story的一个描述性标签
# 选择运行你要执行features的用例
pytest --alluredir ./report/allure --allure-features=模块2
# 选择运行你要执行features的用例
pytest --alluredir ./report/allure --allure-stories="用户故事:1"
总结
以上就是pytest+allure关于测试用例描述的基本使用方法。
如果对你有帮助或喜欢自动化测试开发的朋友,可以加入右下方QQ交流群学习与探索,更多干货与你分享。
相关文章
- pytest fixtures_pytest命令
- pytest 执行用例_pytest怎么指定部分用例执行
- pytest的使用_pytest怎么指定部分用例执行
- pytest parametrize fixture_参数化方法
- pytest skipif_skip的中文是什么
- Pytest(13)命令行参数–tb的使用
- Pytest(1)安装与入门[通俗易懂]
- Pytest(18)pytest接口自动化完整框架思维导图[通俗易懂]
- pytest重试_微信加载插件失败怎么办
- pytest-allure_什么是思想报告
- 利用pytest hook函数实现自动化测试结果推送企业微信
- Python pytest测试框架详解
- pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
- 测试之路 pytest接口自动化-request包中的headers覆盖
- 接口测试第10讲:基pytest框架requests自动化测试
- pytest文档82 - 用例收集钩子 pytest_collect_file 的使用
- pytest + yaml 框架 - 1.我们发布上线了!
- Python 自动化测试框架unittest与pytest的区别
- Pytest学习笔记2——前后置处理高级函数Fixture(完整篇)
- pytest学习和使用8-fixture如何实现teardown功能?(yield的使用)
- pytest学习和使用10-Pytest中的测试用例如何跳过执行?
- pytest学习和使用14-Pytest用例执行结果有哪几种状态?