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

D95【python 接口自动化学习】- pytest进阶之fixture用法

day95 pytest的fixture详解(二)

学习日期:20241210

学习目标:pytest基础用法 -- pytest的fixture详解(二)

学习笔记:

fixture(autouse=True)
  • func的autouse是TRUE时,所有函数方法都会调用func
import pytest
import requests@pytest.fixture(autouse=True)
def func():print("我是前置步骤")def test_getmobile(func):print("测试get请求")params = {'key1': 'value1', 'key2': 'value2'}r=requests.get('https://httpbin.org/get',params=params)print(r.status_code)assert r.status_code == 200res = r.json()assert res['url'] == 'https://httpbin.org/get?key1=value1&key2=value2'assert res['origin'] == '163.125.202.248'assert res['args']['key1'] == 'value1'assert res['args']['key2'] == 'value2'def test_postmobile():print("测试post请求")params = {'key': 'value'}r = requests.post('https://httpbin.org/post', data=params)print(r.status_code)assert r.status_code == 200print(r.json())res=r.json()assert res['args'] == {}assert res['data'] == ''assert res['form']['key'] == 'value'if __name__ == '__main__':pytest.main()
总结
  1. @pytest.fixture(autouse=True),func的autouse是TRUE时,所有函数方法都会调用func
http://www.lryc.cn/news/501893.html

相关文章:

  • Abaqus断层扫描三维重建插件CT2Model 3D V1.1版本更新
  • 隐式对象和泛型
  • CSS的颜色表示方式
  • 单链表常见面试题 —— LeetCode
  • Pydantic中的discriminator:优雅地处理联合类型详解
  • pgloader SQLSERVER -> PostgreSQL 配置文件样例
  • APP、小程序对接聚合广告平台,有哪些广告变现策略?
  • HarmonyOs DevEco Studio小技巧39-模拟器的使用
  • 【C语言】浮点数的原理、整型如何转换成浮点数
  • TesseractOCR-GUI:基于WPF/C#构建TesseractOCR简单易用的用户界面
  • Elasticsearch高性能实践
  • 软件测试--录制与回放脚本
  • nodejs 06.npm的使用以及package.json详解
  • 如何使用WinCC DataMonitor基于Web发布浏览Excel报表文档
  • 颜色的基本处理
  • 跟李笑来学美式俚语(Most Common American Idioms): Part 66
  • 爬虫技术简介
  • 如何打开Windows10的设备管理器
  • scala列表
  • c++检查某一文件是否存在
  • Scala的隐式类,隐式参数和值,隐式对象
  • LabVIEW实现HTTP通信
  • 【EXCEL】 获取多列中 不为空的那一个数据
  • VBA API 概述 | 宏编程
  • pythonOpenCV篇:0基础带你python入门之常用函数
  • 第十七届山东省职业院校技能大赛 中职组“网络安全”赛项资源任务书样题③
  • 【每日一题 基础题】验证回文串
  • 【Hadoop】-- hadoop3.x default port
  • SQL Server:只有MDF文件,如何附加数据库
  • 深入理解代理模式(Proxy):静态代理、动态代理与AOP