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

day101 pytest的fixture执行顺序

学习日期:20241218

学习目标:pytest基础用法 -- pytest的fixture执行顺序

学习笔记:

fixtrue的作用范围
实战结果
python 复制代码
import pytest


@pytest.fixture(scope='session')
def test_session():
    print('我是 session fixture')

@pytest.fixture(scope='module')
def t_module():
    print('我是 module fixture')

@pytest.fixture(scope='function')
def t_function():
    print('我是 function fixture')

@pytest.fixture(scope='class')
def t_class():
    print('我是 class fixture')

class TestOrder:
    def test_order(self,t_class,t_function,test_session,t_module):
        assert 1==1
总结
  1. fixture的作用范围:session>module>class>function
相关推荐
Swizard4 小时前
别再让你的 Python 傻等了:三分钟带你通过 asyncio 实现性能起飞
python
Darkershadow5 小时前
python学习之串口通信
python·学习
3824278276 小时前
python:输出JSON
前端·python·json
也许是_7 小时前
大模型应用技术之 详解 MCP 原理
人工智能·python
沙漠豪7 小时前
提取PDF发票信息的Python脚本
开发语言·python·pdf
F_D_Z9 小时前
【Python】家庭用电数据的时序分析
python·数据分析·时序分析·序列分解
a程序小傲9 小时前
蚂蚁Java面试被问:注解的工作原理及如何自定义注解
java·开发语言·python·面试
love530love9 小时前
【笔记】ComfyUI “OSError: [WinError 38] 已到文件结尾” 报错解决方案
人工智能·windows·python·aigc·comfyui·winerror 38
lcreek9 小时前
LeetCode215. 数组中的第K个最大元素、LeetCode912. 排序数组
python·算法·leetcode