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
相关推荐
Java后端的Ai之路3 分钟前
09、Python组合模式
开发语言·人工智能·python·docker·组合模式
Tenifs8 分钟前
Python Loguru 使用指南
python·loguru
青 春 记 忆12 分钟前
零基础入门python36:用 Django Session 实现购物车
python·django·后端开发
l12586528 分钟前
# LangGraph Tool Calling Agent 深度实战:从零构建 ReAct 循环与工具调用链
人工智能·python·自然语言处理·langchain·agent
reasonsummer37 分钟前
【办公类-119-03】20260901三个园区“国旗下讲话” 按班级组合docx模板(AI+excel+python、deepseek和豆包、微信自动私发)
python
慢云智慧空间43 分钟前
从设备联网到空间理解,智能建筑的系统架构正在经历哪些关键变化?
python·系统架构
磁场转动100万匹3 小时前
PyTorch 手写数字识别实战:从数据加载到模型训练(零基础详解版)
人工智能·pytorch·python
青 春 记 忆9 小时前
零基础入门python30:Flask个人账本从空目录运行与阶段验收
python·flask·后端开发
l1258659 小时前
# LangGraph Memory机制深度解析:短期记忆与长期记忆的工程实践
前端·人工智能·python·langchain·bootstrap