当前位置: 首页 > article >正文

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环境:


http://www.kler.cn/a/5494.html

相关文章:

  • MySQL常用指令--数据过滤、用通配符进行过滤
  • ChatGPT 本地部署及搭建
  • ElasticSearch序列 - SpringBoot整合ES:根据指定的 ids 查询
  • CNStack 网络插件:hybridnet 的设计与实现
  • 程序员的天花板到底有多高?
  • 【数据分析之道-基础知识(八)】循环语句
  • Redis:redis通用命令;redis常见数据结构;redis客户端;redis的序列化
  • 209. 长度最小的子数组
  • 现在大专生转IT可行吗?
  • 枚举的使用
  • 数据结构详解
  • 一文读懂Can总线
  • 容器技术Docker
  • 手写vuex4源码(四)模块的状态的实现
  • Pyspark_结构化流2
  • 数据的存储--->【大小端字节序】(Big Endian)(Little Endian)
  • Python —— 给女儿写个雷霆战机
  • 命令行上的数据科学第二版:十、多语言数据科学
  • Leetcode.1849 将字符串拆分为递减的连续值
  • 第二十八章 变换坐标总结