allure之pytest

pytest运行设置文件

1、文件名:tox.ini或pytest.ini

[pytest]
# command
addopts = -s --alluredir report --clean-alluredir
# search path
testpaths = ./Scripts
# search file
python_files = test_login.py
# search classes
python_classes = Test*
# search function
python_functions = test*

安装pytest和html报告插件

1、安装pytest

pip3 install pytest -i "https://pypi.doubanio.com/simple/"

2、安装html

pip install pytest-html -i "https://pypi.doubanio.com/simple/"

3、使用方法

pytest --html=./report\abc.html

安装修改测试方法默认执行顺序插件

1、安装插件

pip install pytest-ordering -i "https://pypi.doubanio.com/simple/"

2、使用方法(装饰)

@pytest.mark.run(order=n) , n代表顺序

安装失败重试插件

1、安装插件

pip install pytest rerunfailures -i "https://pypi.doubanio.com/simple/" 

2、使用方法

pytest --reruns n(n代表重试几次,一般为2),运行结果:R代表重试

安装allure测试报告

1、安装插件

pip install allure-pytest -i "https://pypi.doubanio.com/simple/"

2、使用方法

pytest --alluredir report (生成为json报告)

–下一步:把allure-2.13.0放在纯英文路径,配置bin目录环境变量
–下一步:执行转换命令:allure generate json报告文件夹 -o ./html文件夹 --clean
注意:

  1. json报告文件夹:由 --alluredir 生成的
  2. html文件夹: 自定义结果:会生成一个html文件夹,里面index.html就是报告。

pytest框架基本使用

setup:函数级别,置于class内。
setup_class:类级别,置于class内。
setup_module:模块级别,置于class外。

列表推导式-断言

1、举例

assert “普通” in [i.text for i in results]

工厂函数

1、定义工厂函数:@pytest.fixture(name=“”) 不写name默认引用函数名=工厂函数名

2、引用:def test_01(self,name1,name2) 或函数引用: @pytest.mark.usefuxtures(“name”)。

3、注:工厂函数优先级高于方法级别初始化方法,低于类级别初始化方法。

4、另:@pytest.fixture(autouse=True) #工厂函数不调用,自运行。
@pytest.fixture(scope=“function”, autouse=Ture) #每个测试方法之前运行一次
@pytest.fixture(scope=“class”, autouse=Ture) #整个类开始只 运行一次

跳过测试方法(跳过不会执行)

@pytest.mark.skipif(条件,reason=“原因”)
1、条件为真 + 有原因 = 跳过
2、条件为假 + 有原因 = 执行
3、无条件 + 有原因 = 执行
4、无条件 + 无原因 = 跳过

预期失败方法(还会执行)

@pytest.mark.xfail(条件,reason=“原因”) xpassed, xfailed

参数化

@pytest.mark.parametrize(argnames,argvalues)
# argnames:参数,单个/多个
# argvalues:参数值(必须为list)
# 当参数为一个时,参数值格式:[value1,value2,value3]
# 当参数为多个时,参数值格式:[(va1,va2),(va1,va2),(va1,va2)]

添加测试步骤

@allure.step("我是操作步骤1")

添加测试描述

allure.attach("我是附件的内容",“附件名字”)

添加严重级别

@allure.severity(Severity)
参数:Severity:严重级别(BLOCKER,CRITICAL,NORMAL,MINOR,TRIVIAL)
使用方式:@allure.severity(allure.severity_level.CRITICAL)

持续集成:

PATH=$PATH;C:\python36\Scripts
pytest

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值