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
相关推荐
做运维的阿瑞4 小时前
用 Python 构建稳健的数据分析流水线
开发语言·python·数据分析
左师佑图4 小时前
综合案例:Python 数据处理——从Excel文件到数据分析
开发语言·python·数据分析·excel·pandas
l1t5 小时前
利用DeepSeek修改数据结构提升求解集合程序效率
数据结构·python·deepseek
jiushun_suanli5 小时前
PyTorch CV模型实战全流程(一)
人工智能·pytorch·python
2301_764441336 小时前
基于python构建的低温胁迫实验
开发语言·python
天才测试猿6 小时前
Selenium定位元素的方法css和xpath的区别
css·自动化测试·软件测试·python·selenium·测试工具·测试用例
云烟成雨TD6 小时前
NumPy 2.x 完全指南【四十二】线性代数之向量运算
python·机器学习·numpy
m0_738120726 小时前
网络安全编程——开发一个TCP代理Python实现
python·tcp/ip·安全·web安全·网络安全
PONY LEE8 小时前
Flink keyby使用随机数踩坑记
大数据·python·flink