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
相关推荐
张张123y2 分钟前
后端第十一课:RAG 落地实战(从 0 到 1 接上私有知识库,并设计一个好用的 RAG)
开发语言·人工智能·python·机器学习·fastapi·rag
golang学习记7 分钟前
Python vs Go:2026年到底该怎么选
java·vscode·python·golang·pycharm·goland
江厌0122 分钟前
移动工作站还是塔式?用三个数判断工位形态,再谈配置
python·移动工作站·塔式工作站·工作站选型·isv认证
川石课堂软件测试26 分钟前
涨薪技术|0到1学会性能测试第8课-Analysis分析图
服务器·数据库·python·sql·jmeter·mysql·容器
学编程的小程31 分钟前
服务器日志太分散不好查?我用Promtail+Loki+Grafana把采集、查询和分析串起来了
服务器·python·grafana
云水初43 分钟前
【项目篇】基于LanGraph的自动处理客服邮件的 Agent汇总
开发语言·笔记·python·学习·fastapi·langgraph
香吧香1 小时前
venv 详解
python
笨笨饿1 小时前
#142_VS Code.map文件插件的用法
git·python·stm32·单片机·嵌入式硬件·物联网·vim
zwd20051 小时前
Manim 竖屏 1080×1920 配置详解:pixel_width、frame_width 怎么写(0.21.0 / 0.22.0 实测)
python·manim·数学动画·短视频制作·manim教程·竖屏视频