当前位置: 首页 > news >正文

测试框架pytest教程(7)实现 xunit 风格的setup

pytest支持setup和teardown,对于使用unittest和nose框架的用户来说对这些很熟悉,但是在pytest可以使用功能更强大的fixture来实现固定装置。

模块级别

如果单个模块中有多个测试函数和测试类,您可以选择实现以下固定方法,这些方法通常会为所有函数调用一次:

def setup_module(module):"""setup any state specific to the execution of the given module."""def teardown_module(module):"""teardown any state that was previously setup with a setup_modulemethod."""
 

 类级别

在调用类的所有测试方法之前和之后,在类级别调用以下方法

@classmethod
def setup_class(cls):"""setup any state specific to the execution of the given class (whichusually contains tests)."""@classmethod
def teardown_class(cls):"""teardown any state that was previously setup with a call tosetup_class."""

方法级别

在每个方法调用周围都会调用以下方法

def setup_method(self, method):"""setup any state tied to the execution of the given method in aclass.  setup_method is invoked for every test method of a class."""def teardown_method(self, method):"""teardown any state that was previously setup with a setup_methodcall."""

直接在模块中定义

def setup_function(function):"""setup any state tied to the execution of the given function.Invoked for every test function in the module."""def teardown_function(function):"""teardown any state that was previously setup with a setup_functioncall."""

http://www.lryc.cn/news/137495.html

相关文章:

  • 用队列实现栈
  • Anolis 8.6 下 Redis 7.2.0 集群搭建和配置
  • 综合能源系统(8)——综合能源系统支撑技术
  • MySQL5.7数据目录结构
  • Python Opencv实践 - 图像直方图均衡化
  • GAN:对抗生成网络,前向传播和后巷传播的区别
  • 压力变送器的功能与应用
  • 排序算法:选择排序
  • Windows运行Spark所需的Hadoop安装
  • KusionStack使用文档
  • ONLYOFFICE 文档如何与 Alfresco 进行集成
  • PostgreSQL下载路径与安装步骤
  • 如何在PHP中编写条件语句
  • LLM架构自注意力机制Transformers architecture Attention is all you need
  • 计算机网络 QA
  • 安果天气预报 产品介绍
  • net start Mysql 启动服务时 ,显示“Mysql服务正在启动 Mysql服务无法启动 服务没有报告任何错误
  • DAY24
  • Redis过期数据的删除策略
  • 如何使用CSS实现一个拖拽排序效果?
  • leetcode 118.杨辉三角
  • 微服务框架之SpringBoot面试题汇总
  • Promise详解
  • Oracle 查询(当天,月,年)的数据
  • 什么是梯度下降
  • 开黑啦kook 机器人开发 PHP swoole Liunx 服务器(宝塔)
  • Vue 中hash 模式与 history 模式的区别
  • Dockerfile推送私有仓库的两个案例
  • 【指标】指标公式大全,款款经典(建议珍藏)!-神奇指标网
  • 面试题目收集