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
相关推荐
带娃的IT创业者41 分钟前
WeClaw 离线消息队列实战:异步任务队列如何保证在服务器宕机时不丢失任何一条 AI 回复?
运维·服务器·人工智能·python·websocket·fastapi·实时通信
坐吃山猪2 小时前
Python进度条
linux·服务器·python
l1t3 小时前
四种python工具包用SQL查询csv和parquet文件的方法比较
大数据·python·sql
清水白石0083 小时前
Python 并发三剑客:多线程、多进程与协程的实战抉择
java·服务器·python
2301_793804693 小时前
更优雅的测试:Pytest框架入门
jvm·数据库·python
dinl_vin3 小时前
python:常用的基础工具包
开发语言·python
wefly20173 小时前
无需安装、开箱即用!m3u8live.cn 在线 HLS 播放器,调试直播流效率翻倍
前端·后端·python·前端开发工具·后端开发工具
2301_815482934 小时前
用Python实现自动化的Web测试(Selenium)
jvm·数据库·python
将心ONE4 小时前
melo tts安装使用
python
宸翰5 小时前
Python学习:年轻人的第一个入门Python项目(FastAPI版)
后端·python