PyTest_Allure企业定制

第三篇

allure部署

$ wget 	https://github.com/allure-framework/allure2/releases/download/2.17.3/allure-2.17.3.tgz
$ vim   ~/.bash_profile  

#allure变量
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
export PATH=/Users/bytedance/Downloads/allure-2.17.3/bin:$PATH
export
$ source ~/.bash_profile
$ allure --version 
2.17.3

allure的私人定制

获取tar.gz包,解压,配置变量,版本查看

allure配置文件详解

bin执行文件
config主配置文件
libjar包
Plugins插件

LOG定制:

1、进入到allure目录,切换config目录,进入allure.yml,添加开启custom-logo-plugin插件

plugins:
  - junit-xml-plugin
  - xunit-xml-plugin
  - trx-plugin
  - behaviors-plugin
  - packages-plugin
  - screen-diff-plugin
  - xctest-plugin
  - jira-plugin
  - xray-plugin
  - custom-logo-plugin				#添加内容

2、切换/plugins/custom-logo-plugin/static/下,修改配置文件

$ tree
.
├── custom-logo.svg		#默认log
├── styles.css				#allure读取log文件
└── zjtd.png					#要指定的log
/* .side-nav__brand {
  background: url('custom-logo.svg') no-repeat left center !important;
  margin-left: 10px;
} */

.side-nav__brand {
  background: url('zjtd.webp') no-repeat left center !important;
  margin-left: 10px;
  height: 90px;
  background-size: contain !important;
}
.side-nav__brand-text{
  display: none;
}
  • background: log的名称
  • margin-left: 左外边距
  • height: 身高
  • background-size: 背景尺寸

Allure功能定制:

功能区的定制都是通过装饰器来实现

左边区域-功能区
@allure.epic(“项目名称”)项目名称定制
@allure.feature(“项目模块名称”)项目模块名称定制
@allure.story(“测试用例名称”)项目用例名称定制
@allure.title(“测试用例标题”)项目用例的标题定制—1
allure.dynamic.title(“用例标题”)项目用例的标题定制—2
右边区域-功能区
@allure.severity(allure.severity_level.严重级别)项目测试用例优先级制定
allure.dynamic.description(“描述内容”)项目用例的描述信息
@allure.link(“www.baidu.com”) # 接口地址
@allure.testcase(“www.baidu.com”) # 用例地址
@allure.issue(“www.baidu.com”) # BUG地址
项目用例的链接信息

左边

项目名称定制:

@allure.epic("项目名称")

项目模块名称定制:

@allure.feature("项目模块名称")

项目用例名称定制:

@allure.story("测试用例名称")

项目用例的标题定制:

@allure.title("测试用例标题")

另外一种方式:

allure.dynamic.title("用例标题")

右边

优先级制定:

@allure.severity(allure.severity_level.严重级别)
级别:
    BLOCKER = 'blocker'		#知名
    CRITICAL = 'critical'	#严重
    NORMAL = 'normal'			#一般
    MINOR = 'minor'				#提示
    TRIVIAL = 'trivial'		#轻微

项目用例的描述信息:

allure.dynamic.description("描述内容")

项目用例的链接信息:

@allure.link("www.baidu.com")       # 接口地址
@allure.testcase("www.baidu.com")   # 用例地址
@allure.issue("www.baidu.com")      # BUG地址

项目用例的测试步骤:

#测试步骤
for a in range(1, 6):
    with allure.step("执行第" + str(a) + "个步骤"):
        pass

项目用例的错误截图&文本信息:

# 附件
with open(r"/Users/bytedance/Downloads/allure-2.17.3/plugins/custom-logo-plugin/static/zjtd.png",
          mode="rb") as f:
    content = f.read()
    allure.attach(body=content, name="错误截图🙅", attachment_type=allure.attachment_type.PNG)
    print("case----3---删除用户")
# 文本
allure.attach(body="接口地址:j8.com", name="接口地址", attachment_type=allure.attachment_type.TEXT)

局域网开放allure报告访问:

$ allure open ./report_2022_04_02_11_18_35--clean 
Starting web server...
2022-04-02 11:34:31.748:INFO::main: Logging initialized @894ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://192.168.2.104:56469/>. Press <Ctrl+C> to exit

装饰器parametrize+yaml实现数据驱动

    @pytest.mark.parametrize("args_name", ["张三", "李四", "王武"])
    def test_wx_parmas_01(self, args_name):
        print("参数化:")

    @pytest.mark.parametrize("args_name,args_age", [["张三", "18"], ["李四", "18"], ["王武", "18"]])
    def test_wx_parmas_02(self, args_name, args_age):
        print("参数化:", args_name, args_age)

YAML:

yaml是一种数据格式,分为两种写法:

map对象:

name: 张三

list列表:

- name01: 张三
- name02: 李四
- name03: 王五

通过pyyaml配合parametrize来实现数据驱动

下载pyyaml模块,在项目目录写一个数据驱动读取yaml文件

$ pip3 install pyyaml                            

新建一个公共读取的包commns新建读取yaml的工具包yaml_util.py

# 读取yaml文件
import yaml


def read_yaml(yaml_path):
    with open(yaml_path, mode='r', encoding='utf-8') as f:
        value = yaml.load(f, Loader=yaml.FullLoader)
        return value

通过parametrize装饰器来读取yaml方法

@pytest.mark.parametrize("args_name", read_yaml(".//test_case_all/test_wx/get_token.yaml"))
def test_wx_parmas_03(self, args_name):
    print("参数化:")

.//test_case_all/test_wx/get_token.yaml #数据驱动读取的文件

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值