pytest基础用法

项目中需要,只记录目前需要的功能,后面会陆续补充

安装 pip install pytest

使用:
1。配置文件

[pytest]

addopts = -s
testpaths = ./test_case
python_files = test_.py
python_class = Test

python_functions = test_*

这其实是默认配置。

  1. @pytest.mark.skip(reason=“”) 跳过,可加reason
    @pytest.mark.skipif() 判断条件跳过
    @pytest.mark.xfail(raise=ZeroDivisionError) 标记预期失败

  2. @pytest.mark.parametrize([‘a’,‘b’],[[],[],[],[],[]]) 前面形参,后面实参

  3. 夹具:
    模块级别:
    setup_module
    teardown_module

    类级别:
    setup_class
    teardown_class

    实例级别:
    setup_function
    teardown_function

    方法级别:
    setup_method
    teardown_method

    默认为方法级别:
    setup
    teardown

  4. 失败重跑
    需要装插件:
    pip install pytest-rerunfailures
    运行方式:
    命令行:pytest --reruns 5
    配置文件方式:
    addopts = -s --reruns 5

  5. 失败截图

  6. allure结合使用
    windows环境:
    pip install allure-pytest
    allure包下载:https://github.com/allure-framework/allure2/releases
    解压 -> 进入bin目录 -> 运行allure.bat,
    把bin目录加入PATH环境变量
    cmd+r 运行一下allure --version看下有没有成功

    centos环境:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值