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

pytest

1、查看版本

import pytest
print(pytest.__version__)
运行结果:8.4.1
print(pytest.version_tuple)
运行结果:(8, 4, 1)

2、常用函数

  • pytest.skip
方法1:
# 使用带有可选 skip 装饰器标记,该装饰器可以传递一个可选的 reason 参数:
@pytest.mark.skip(reason="no way of currently testing this")
def test_the_unknown(): ...方法2:
# 在测试执行或设置过程中通过调用 pytest.skip(reason) 函数来显式跳过
def test_function():if not valid_config():pytest.skip("unsupported configuration")
  • pytest.skip
# 根据条件跳过某些内容import sys
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
def test_function(): ...
  • pytest.fail——标记测试函数为预期失败
方法1:
@pytest.mark.xfail(reason="xxxxx")
def test_function(): ...方法2:
def test_function():if not valid_config():pytest.xfail("failing configuration (but should work)")
  • pytest.exit()——结束测试进程
  • pytest.param()——在 pytest.mark.parametrize 调用或 参数化 fixture 中指定参数。
  • pytest.raises——异常断言

3、常用标记

  pytest.mark.parametrize——参数化

  pytest.mark.skip——跳过

  pytest.mark.skipif——有条件的跳过

  pytest.mark.usefixtures——将测试函数标记为使用指定的 fixture 名称

  pytest.mark.xfail——标记为预期失败

4、测试夹具

  @pytest.fixture

    scope –该 fixture 共享的范围

    params – 一个可选的参数列表

    autouse – 如果为 True,则 fixture func 对所有能看见它的测试都生效

    name – 固定装置的名称

 

http://www.sczhlp.com/news/12567/

相关文章:

  • Git创建本地远程仓和局域网远程仓
  • OI集训 Day30
  • 把时间当作朋友:知识获取的终极法则
  • Zephyr学习:3.DeviceTree学习
  • 如何让Typecho搭建的网站首页文章随机显示?各位大佬支支招!
  • 柯马弧焊机器人气流智能调节
  • IIS安装URL重写组件(URL Rewrite)
  • 13KB JavaScript太空射击游戏开发解析
  • 点分治与点分树 专题
  • 《白话机器学习的数学》-多项式回归与正则化
  • CatoiOS3.0权限系统设计
  • A,B,C计权声级测试说明
  • PostgreSQL技术大讲堂 - 第101讲:AI4DB--让AI生成SQL语句
  • 混合红蓝队训练实验室搭建指南:基于VirtualBox的网络安全实战环境
  • 走进SAP系统管理下的数字工厂:看制造企业如何推进车间精益生产?
  • 使用RDKStudio使用教程
  • COS MCP Server,打造 AI 时代的存储与处理智能枢纽
  • SpringBoot3集成Swagger
  • 关于APx500 软件测试音 频的参数设置及相应的步骤
  • qiankun微前端使用指南-总结
  • TF 上架流程全解析,跨平台团队如何用 TestFlight 实现上架 iOS App
  • 深黯Solution
  • Azkaban启用常见问题说明(启动报错)
  • 接入提供方的AI
  • 使用 MetaWeblog API 修改博客
  • Poste.io自建域名的邮箱本地化部署方案 - 明明就
  • vscode里退出github Copilot账号,切换github Copilot账号,completion quota用完了,显示100%,vscode不能自动补全
  • Grain用于读取和处理用于训练和评估 JAX 模型的数据
  • 华三-OSPF
  • 嘉立创地阔星STM32F103C8T6 arduino ch340串口烧录