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
相关推荐
紫丁香几秒前
pytest_自动化测试1
开发语言·python·功能测试·单元测试·pytest
姚青&几秒前
Pytest 测试用例生命周期管理-自动生效(autouse)
测试用例·pytest
酷酷的橙子1 分钟前
python 学习
python
姚青&4 分钟前
Pytest 测试用例执行顺序自定义 Pytest-ordering
测试用例·pytest
Sakuraba Ema9 分钟前
Attention Residuals:把固定残差换成“跨层注意力”
python·llm·attention
独隅10 分钟前
Python 标准库 (Standard Library) 全面使用指南
android·开发语言·python
姓王名礼15 分钟前
模拟发票,发票PDF
python
@我漫长的孤独流浪20 分钟前
Python精选480题带解析
python
cyforkk29 分钟前
Spring AOP 核心揭秘:ProceedingJoinPoint 与反射机制详解
java·python·spring
2301_8101609533 分钟前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python