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
相关推荐
Data_Journal7 小时前
用于网页抓取的 Node-unblocker
大数据·开发语言·数据库·python·scrapy
豆角焖肉8 小时前
SSM 聚合项目搭建:多 Maven 模块项目
开发语言·python·pycharm
青 春 记 忆8 小时前
零基础入门python20:Flask配置、扩展和蓝图拆分
python·flask·后端开发
m0_380743879 小时前
为 OpenAI 兼容接口配置教程
开发语言·python·node.js
leisoo809710 小时前
ig50数据落盘ClickHousevsTimescaleDBvsDuckDB实测对比 IG50免费开源股票数据API接口
开发语言·jvm·数据库·python·json
卷无止境10 小时前
FastAPI 的 Metadata 到底是什么,又牵动了哪些核心概念
后端·python
卷无止境11 小时前
FastAPI 调试实战,从断点到生产环境的排错心法
后端·python
yaoxin52112311 小时前
503. Java 反射 - 编写 ServiceFactory 类
java·开发语言·python
kyrie_sakura12 小时前
python学习笔记3 -- 流程控制语句结构
笔记·python·学习
冷凝娇12 小时前
【Pytest】2026 学习总结
学习·pytest