栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Pytest装饰器使用(一)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Pytest装饰器使用(一)

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录
  • 前言
  • 一、@pytest.mark.skip(reason)
  • 二、@pytest.skip(msg)
  • 三、@pytest.mark.skipif(condition,reason)
  • 四、@pytest.mark.xfail(reason)
  • 五、@pytest.mark.run(order)


前言

在UI自动化测试过程中会使用到pytest相关装饰器,本文主要介绍自己工作过程中使用到的装饰器


一、@pytest.mark.skip(reason)

设置跳过用例用于函数体外,可用于标注功能暂未实现的用例

import pytest
@pytest.mark.skip(reason="测试跳过")
def test001():
    print('test001')
def test002():
    print('test002')
pytest.main()
二、@pytest.skip(msg)

用例执行过程中若条件不成立时跳出当前用例,用于函数体内

import pytest
def test001():
    if 2 > 1:
        pytest.skip("条件成立")
    print('test001')
pytest.main()
三、@pytest.mark.skipif(condition,reason)

根据条件跳过用例,用于类方法和具体函数,可以用于归类用例,限定条件来执行对应用例数据

import pytest
condition='monica'
@pytest.mark.skipif(condition=='monica',reason='测试跳过')
def test002():
    print('test002')
pytest.main()
四、@pytest.mark.xfail(reason)

该方法主要用到某些场景bug未修复或者用例存在问题可以直接标注为失败状态

import pytest
@pytest.mark.xfail(reason='测试标注失败')
def test001():
    print('用例1')
def test002():
    print('用例2')
pytest.main()
五、@pytest.mark.run(order)

设置用例执行顺序,数字越小优先执行

import pytest
#pytest装饰器
@pytest.mark.run(order=1)
def test002():
    print('用例2')
@pytest.mark.run(order=2)
def test001():
    print('用例1')
pytest.main()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/998225.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号