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
相关推荐
咖啡の猫7 小时前
Python字典推导式
开发语言·python
曹文杰15190301127 小时前
2025 年大模型背景下应用统计本科 计算机方向 培养方案
python·线性代数·机器学习·学习方法
Wulida0099917 小时前
建筑物表面缺陷检测与识别:基于YOLO11-C3k2-Strip模型的智能检测系统
python
FJW0208148 小时前
Python_work4
开发语言·python
爱笑的眼睛118 小时前
从 Seq2Seq 到 Transformer++:深度解构与自构建现代机器翻译核心组件
java·人工智能·python·ai
yaoh.wang9 小时前
力扣(LeetCode) 88: 合并两个有序数组 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·双指针
执笔论英雄9 小时前
【RL】slime创建actor的流程
python
吴佳浩 Alben9 小时前
Python入门指南(四)
开发语言·后端·python
小智RE0-走在路上9 小时前
Python学习笔记(8) --函数的多返回值,不同传参,匿名函数
笔记·python·学习
ZHSH.10 小时前
2026蓝桥杯备赛 | 赛事介绍及python基础(未完)
python·蓝桥杯·数据结构与算法