脚本宝典收集整理的这篇文章主要介绍了Pytest系列(23)- allure 打标记之 @allure.epic()、@allure.feature()、@allure.story() 的详细使用,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
提供了三个装饰器
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ =
__Time__ = 2020-04-19 14:27
__Author__ = 小菠萝测试笔记
__BLOG__ = https://www.cnblogs.com/poloyy/
"""
import allure
def test_without_any_annotations_that_wont_be_executed():
pass
@allure.story('epic_1')
def test_with_epic_1():
pass
@allure.story('story_1')
def test_with_story_1():
pass
@allure.story('story_2')
def test_with_story_2():
pass
@allure.feature('feature_2')
@allure.story('story_2')
def test_with_story_2_and_feature_2():
pass
我们先看看没有设置标记装饰器时,allure报告是咋样的
加了 @allure.feature 和 @allure.story 之后的 allure 报告
这里应用了包括前面所讲的全部装饰器
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ =
__Time__ = 2020/10/27 19:44
__Author__ = 小菠萝测试笔记
__Blog__ = https://www.cnblogs.com/poloyy/
"""
import os
import allure
import pytest
@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 相当于总体描述")
@allure.feature("测试模块")
class TestAllureALL:
@allure.testcase("https://www.cnblogs.com/poloyy/", '测试用例,点我一下')
@allure.issue("https://www.cnblogs.com/poloyy/p/12219145.html", 'Bug 链接,点我一下')
@allure.title("用例的标题")
@allure.story("story one")
@allure.severity("critical")
def test_case_1(self, login_fixture):
"""
小菠萝测试笔记地址:https://www.cnblogs.com/poloyy/
"""
print("测试用例1")
step_1()
step_2()
@allure.story("story two")
def test_case_2(self, login_fixture):
print("测试用例2")
step_1()
step_3()
@allure.epic("另一个 epic")
@allure.feature("查找模块")
class TestAllureALL2:
@allure.story("story three")
def test_case_3(self, login_fixture):
print("测试用例3")
step_1()
@allure.story("story four")
def test_case_4(self, login_fixture):
print("测试用例4")
step_3()
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './allure'])
os.System('allure -c ./allure')
os.system('allure serve ./allure-report')
倘若是用 pytest+allure 写项目,又想用 @pytest.mark.xxx 来给不同的用例添加标记的话,可以尝试用 @allure.feature、@allure.story 替换,毕竟可以显示在报告上
用命令行方式运行时,可以指定运行某个story、feature、epic吗?
当然可以,跟 @pytest.mark.xxx 指定标签运行的方式没啥区别,添加下面的命令行参数就行
# 只运行 epic 名为 test 的测试用例
pytest --alluredir ./report/allure --allure-epics=test
# 只运行 feature 名为 模块 的测试用例
pytest --alluredir ./report/allure --allure-features=模块
# 只运行 story1、story2 的测试用例(也可以不用=号 空格就行了哦)
pytest tests.py --allure-stories story1,story2
# 指定 feature+story
pytest tests.py --allure-features feature2 --allure-stories story2
以上是脚本宝典为你收集整理的Pytest系列(23)- allure 打标记之 @allure.epic()、@allure.feature()、@allure.story() 的详细使用全部内容,希望文章能够帮你解决Pytest系列(23)- allure 打标记之 @allure.epic()、@allure.feature()、@allure.story() 的详细使用所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。