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
相关推荐
GEOshijie12314 小时前
GEO服务商算法适配承诺怎么验收?48小时响应的合同化考核方案
人工智能·python
卷无止境15 小时前
FastAPI 前端托管全攻略:从静态文件到大型全栈项目架构
后端·python
QQ54164512115 小时前
【驿帮查件助手python开源】开源聚合查件机器人,实现 24 类驿站批量查件取代短信通知。技术方案分享
python·机器人·开源·驿站查件机器人
卷无止境15 小时前
当FastAPI项目开始"膨胀",代码该往哪儿放
后端·python
用户83562907805115 小时前
Python设置PowerPoint幻灯片背景的方法
后端·python
wang_yb15 小时前
Python 中 10 个最常用的统计函数
python·databook
databook15 小时前
Python 中 10 个最常用的统计函数
python·数据分析
艾琳_lab16 小时前
Python环境配置:pip镜像设置
python
橘好き16 小时前
Python
python
鹿鹿学长16 小时前
从英伟达开源Nemotron 3.5看“本地跑大模型“:一张显卡够用的时代来了
python·自动化