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
相关推荐
曲幽26 分钟前
FastAPI单元测试实战:别等上线被喷才后悔,TestClient用对了真香!
python·单元测试·pytest·api·fastapi·web·httpx·testclient·依赖项覆盖
章鱼丸-27 分钟前
DAY34 GPU 训练与类的 call 方法
开发语言·python
小陈工39 分钟前
2026年3月24日技术资讯洞察:边缘AI商业化,Java26正式发布与开源大模型成本革命
java·运维·开发语言·人工智能·python·容器·开源
qq_4160187241 分钟前
Python多线程与多进程:如何选择?(GIL全局解释器锁详解)
jvm·数据库·python
m0_662577971 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
MORE_771 小时前
leecode100-买卖股票的最佳时期-贪心算法
python·算法·贪心算法
暮冬-  Gentle°1 小时前
用Python制作一个文字冒险游戏
jvm·数据库·python
小小小米粒2 小时前
[特殊字符] 正常部署 AI + 流式输出(Stream)[特殊字符] 为什么会 CPU 炸了?
开发语言·python
站大爷IP2 小时前
Python异步编程:asyncio核心用法与避坑指南
python
m0_587958952 小时前
游戏与图形界面(GUI)
jvm·数据库·python