pytest文档32-allure描述用例详细讲解

前言

pytest+allure是最完美的结合了,关于allure的使用,本篇做一个总结。
allure报告可以很多详细的信息描述测试用例,包括epic、feature、story、title、issue、testcase、severity等
环境准备

  • python 3.6

  • pytest 4.5.0

  • allure-pytest 2.8.6

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测试用例

import pytest
import allure
# 作者:上海-悠悠 qq交流群:874033608

@pytest.fixture(scope="session")
def login_fixture():
print("前置条件:登录")

@allure.step("步骤1")
def step_1():
print("操作步骤---------------1")

@allure.step("步骤2")
def step_2():
print("操作步骤---------------2")

@allure.step("步骤3")
def step_3():
print("操作步骤---------------3")

@allure.epic("epic对大Story的一个描述性标签")
@allure.feature("测试模块")
class TestDemoAllure():

@allure.testcase("http://49.235.x.x:8080/zentao/testcase-view-6-1.html")
@allure.issue("http://49.235.x.x:8080/zentao/bug-view-1.html")
@allure.title("用例的标题")
@allure.story("用户故事:1")
@allure.severity("critical")
def test_case_1(self, login_fixture):
'''case description:作者:上海-悠悠 qq交流群:874033608
1.点文章分类导航标签 -跳转编辑页面
2.编辑页面输入,分类名称,如:上海-悠悠-可以输入
3.点保存按钮保存成功
'''
step_1()
step_2()

@allure.story("用户故事:2")
def test_case_2(self, login_fixture):
print("测试用例1")
step_1()
step_3()

@allure.epic("epic对大Story的一个描述性标签")
@allure.feature("模块2")
class TestDemo2():

@allure.story("用户故事:3")
def test_case_3(self, login_fixture):
print("测试用例1")
step_1()

@allure.story("用户故事:4")
def test_case_4(self, login_fixture):
print("测试用例1")
step_3()

报告展示

cd到用例目录执行用例生成allure报告

pytest —alluredir ./report/allure
allure serve ./report/allure

报告展示内容

命令行参数

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”

关于allure的使用基本上就是这些了
2020年第二期《python接口自动化+测试开发》课程,12月15号开学!

(0)

相关推荐

  • Python Requests Pytest YAML Allure实现接口自动化

    作者:wintest 链接:https://www.cnblogs.com/wintest/p/13423231.html 本项目实现接口自动化的技术选型:Python+Requests+Pytest ...

  • pytest参数化-读取excel allure报告展示

    由于近期公司要求项目接口自动化且使用参数化.装饰器等,我在网上查了一下资料,现在整理下,放便以后代码套用 版本: pytest==6.2.1 pytest-html ==2.1.1 pyyaml == ...

  • pytest文档12-skip跳过用例

    前言 pytest.mark.skip可以标记无法在某些平台上运行的测试功能,或者您希望失败的测试功能 skip意味着只有在满足某些条件时才希望测试通过,否则pytest应该跳过运行测试. 常见示例是 ...

  • pytest文档28-重复执行用例(pytest-repeat)

    前言 平常在做功能测试的时候,经常会遇到某个模块不稳定,偶然会出现一些bug,对于这种问题我们会针对此用例反复执行多次,最终复现出问题来. 自动化运行用例时候,也会出现偶然的bug,可以针对单个用例, ...

  • pytest文档34-Hooks函数改变用例执行顺序(pytest_collection_modifyitems)

    前言 有一些小伙伴一直想改变pytest用例的执行顺序,实际上我们在用例设计原则上用例就不要有依赖顺序. pytest默认执行用例是先根据项目下的文件夹名称按ascii码去收集的,module里面的用 ...

  • pytest文档40-pytest.ini配置用例查找规则(面试题)

    前言 面试题:pytest如何执行不是test开头的用例?如执行 xxx_*.py这种文件的用例. pytest.ini 配置文件可以修改用例的匹配规则. pytest命令行参数 cmd打开输入pyt ...

  • pytest文档47-allure报告添加用例失败截图

    前言 使用 selenium 做 web 自动化的时候,很多小伙伴希望用例失败的时候能截图,把异常截图展示到allure报告里面. pytest 有个很好的钩子函数 pytest_runtest_ma ...

  • pytest文档41-参数化 ids 用例描述为中文时控制台输出unicode

    前言 使用 pytest.mark.parametrize  参数化的时候,加 ids 参数用例描述有中文时,在控制台输出会显示unicode编码,中文不能正常显示. 使用 pytest_collec ...

  • pytest文档2-用例运行规则

    用例设计原则 文件名以test_*.py文件和*_test.py 以test_开头的函数 以Test开头的类 以test_开头的方法 所有的包pakege必须要有__init__.py文件 help帮 ...

  • pytest文档27-运行上次失败用例(--lf 和 --ff)

    前言 "80%的bug集中在20%的模块,越是容易出现bug的模块,bug是越改越多"平常我们做手工测试的时候,比如用100个用例需要执行,其中10个用例失败了, 当开发修复完bu ...

  • pytest文档31-allure标记用例级别severity

    前言 我们在做功能测试的时候,执行完一轮测试用例,输出测试报告的时候,会有统计缺陷的数量和等级. 在做自动化测试的过程中,当你的测试用例越来越多的时候,如果执行一轮测试发现了几个测试不通过,我们也希望 ...