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

@pytest.fixture函数怎么传变量参数

1、使用 params 参数进行参数化
import pytest
@pytest.fixture(params=[1, 2, 3])
def number_fixture(request):
return request.param

def test_with_params(number_fixture):
print(f"Testing with number: {number_fixture}")

2、使用 indirect 参数传递复杂参数
import pytest
@pytest.fixture
def complex_data(request):
return request.param

@pytest.mark.parametrize(‘complex_data’, [
{‘name’: ‘Alice’, ‘age’: 25},
{‘name’: ‘Bob’, ‘age’: 30}
], indirect=True)
def test_complex_data(complex_data):
print(f"Name: {complex_data[‘name’]}, Age: {complex_data[‘age’]}")

  1. fixture 之间传递参数
    import pytest

@pytest.fixture
def complex_data(request):
return request.param

@pytest.mark.parametrize(‘complex_data’, [
{‘name’: ‘Alice’, ‘age’: 25},
{‘name’: ‘Bob’, ‘age’: 30}
], indirect=True)
def test_complex_data(complex_data):
print(f"Name: {complex_data[‘name’]}, Age: {complex_data[‘age’]}")

  1. 使用 request 对象获取参数
    import pytest
    @pytest.fixture
    def complex_data(request):
    return request.param

@pytest.mark.parametrize(‘complex_data’, [
{‘name’: ‘Alice’, ‘age’: 25},
{‘name’: ‘Bob’, ‘age’: 30}
], indirect=True)
def test_complex_data(complex_data):
print(f"Name: {complex_data[‘name’]}, Age: {complex_data[‘age’]}")

http://www.dtcms.com/a/540353.html

相关文章:

  • Excel高性能异步导出完整方案!
  • 网站正在建设 敬请期待免费的cms模板
  • 输电线路绝缘子缺陷检测图像数据集VOC+YOLO格式1578张3类别
  • 跨文化理解的困境与AI大模型作为“超级第三方“的桥梁作用
  • JDK版本管理工具JVMS
  • 【JUnit实战3_18】第十章:用 Maven 3 运行 JUnit 测试(上)
  • SQLite 核心知识点讲解
  • JAiRouter v1.1.0 发布:把“API 调没调通”从 10 分钟压缩到 10 秒
  • 自建网站如何赚钱c2c模式为消费者提供了便利和实惠
  • Lua-编译,执行和错误
  • Lua与LuaJIT的安装与使用
  • 数独生成题目lua脚本
  • 影响网站加载速度wordpress获得当前文章的相关文章
  • Hive 技术深度解析与 P7 数据分析架构师多行业全场景实战课程合集(视频教程)
  • 嘉兴高端网站建设公司网络安全等级保护
  • HOW - localstorage 超时管理方案
  • java如何判断上传文件的类型,不要用后缀名判断
  • 【Linux】系统备份与恢复:rsync 与 tar 的完整使用教程
  • ROS2系列(3):第一个C++节点
  • zookeeper是什么
  • 构建“全链路解决方案”:解决集团化医院信创的三重难题
  • 网站建设区别广安市邻水建设局网站
  • 网站中的文字滑动怎么做化妆品网站建设策略
  • 【Netty4核心原理⑮】【Netty 编解码的艺术】
  • PHP-Casbin 在分布式服务中利用 Watcher 做策略同步
  • OCP考试必须培训吗?费用多少?
  • SpringBoot + 百度内容安全实战:自定义注解 + AOP 实现统一内容审核(支持文本 / 图片 / 视频 + 白名单 + 动态开关)
  • 心智结构与组织学习
  • NAS 私有云零信任部署:cpolar 加密访问 + 本地存储,破解安全与便捷难题
  • C++面向对象继承全面解析:不能被继承的类、多继承、菱形虚拟继承与设计模式实践