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
相关推荐
陪我一起学编程10 分钟前
uv包管理工具
python·uv·虚拟环境·包管理工具·项目工程化·项目规范·pip、conda、pdm
盼哥PyAI实验室10 分钟前
Python自定义HTTP客户端:12306抢票项目的网络请求管理
开发语言·python·http
这儿有一堆花14 分钟前
Python优化内存占用的技巧
开发语言·python
爱笑的眼睛1128 分钟前
PyTorch自动微分:超越基础,深入动态计算图与工程实践
java·人工智能·python·ai
Daily Mirror42 分钟前
Day33 类的装饰器
python
web3.08889991 小时前
震坤行商品详情数据接口可以用于获取商品详情信息
python·计算机网络
Salt_07281 小时前
DAY32 类的定义和方法
开发语言·python·算法·机器学习
Nick_zcy1 小时前
新能源汽车推荐系统分享
爬虫·python·汽车·推荐算法
未来影子1 小时前
Java领域构建Agent新杀入一匹黑马(agentscope-java)
java·开发语言·python