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

pytest笔记2: fixture

 1. fixture 通常是对测试方法和测试函数,测试类整个测试文件进行初始化或是还原测试环境

# 功能函数
def multiply(a, b):return a * b
# ------------ fixture---------------def setup_module(module):print("======setup_module  在当前文件中所有测试用例之前=====")def teardown_module(module):print("======teardown_module 在当前文件中所有测试用例之后=====")def setup_function(function):print("setup_function=====>在每个测试函数之前执行")def teardown_function(function):print("setup_function=====>在每个测试函数之后执行")def setup():print("setup---在每个测试函数之前------>")def teardown():print("teardown----在每个测试函数之后可以作用于类方法----->")# ---------------测试用例-------------def test_mult_3_4():print("test_mult_3_4")assert multiply(3, 4) == 12def test_mult_a_4():print("test_mult_a_3")assert multiply('a', 3) == 'aaa'

 

没有 setup/teardown?

 

2.支持Test 开头的测试类

# 功能函数
def multiply(a, b):return a * bclass TestMultiply:# =====fixtures========@classmethoddef setup_class(cls):print("setup_class=========>")@classmethoddef teardown_class(cls):print("teardown_class=========>")def setup_method(self, method):print("setup_method----->>")def teardown_method(self, method):print("teardown_method-->>")def setup(self):print("setup----->")def teardown(self):print("teardown-->")# =====测试用例========def test_numbers_5_6(self):print('test_numbers_5_6')assert multiply(5, 6) == 30def test_strings_b_2(self):print('test_strings_b_2')assert multiply('b', 2) == 'bb'

 

rootdir: E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example\fixture
plugins: anyio-3.5.0
collected 2 items                                                                                                                                                    test_fixtures_02.py setup_class=========>
setup_method----->>
test_numbers_5_6
.teardown_method-->>
setup_method----->>
test_strings_b_2
.teardown_method-->>
teardown_class=========>

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

相关文章:

  • day55 补
  • CSS变量之var()函数的应用——动态修改样式 root的使用
  • 索尼 toio ™应用创意开发征文|一个理想的绘画小助手
  • java加密,使用python解密 ,使用 pysm4 报 byte greater than 16的解决方法
  • django后台启动CORS跨越配置
  • 异常的顶级理解
  • LinkedHashMap实现LRU缓存cache机制,Kotlin
  • Google 开源库Guava详解(集合工具类)
  • Ansys Zemax | 如何将光线追迹结果导出为IES格式
  • JSONObject 比 Map好使的地方
  • [js] 图解 event.pageX event.clientX event.offsetX getBoundingClientRect
  • VsCode备忘
  • Linux命令200例:Yum强大的包管理工具使用(常用)
  • 使用 Linux 相关知识部署博客系统
  • Linux--进程--vfork与fork区别
  • Ubuntu系统重装nvidia gpu驱动
  • Java + Selenium + Appium自动化测试
  • 【sgLazyCascader】自定义组件:基于el-cascader的懒加载级联菜单,支持异步加载子级菜单
  • 2023高教社杯数学建模E题思路模型 - 黄河水沙监测数据分析
  • 一、Linux下常用的压缩格式
  • MySQL 查询 - 排除某些字段的SQL查询,提升查询性能
  • 国产信创服务器如何进行安全可靠的文件传输?
  • ARTS第五周:S - 数据编织 Data fabric
  • 基于ArcGIS、ENVI、InVEST、FRAGSTATS等多技术融合提升环境、生态、水文、土地、土壤、农业、大气等领域的数据分析能力与项目科研水平教程
  • Spring Boot 介绍
  • mysql基于AES_ENCRYPTAES_DECRYPT实现密码的加密与解密
  • 怎么把pdf转换成jpg图片?
  • 计算机脚本的概念,如何编写、使用脚本 (Script)?
  • c语言 5.0
  • 如何配置远程访问以在外部网络中使用公司内部的OA办公系统——“cpolar内网穿透”