当前位置:网站首页>pytest初始化和清理环境
pytest初始化和清理环境
2022-06-29 22:54:00 【傲娇的喵酱】
一、setup和teardown方式
1、方法级别初始化、清除,每个方法运行前后执行一次
setup 和 teardown,setup_method,teardown_method
2、类级别初始化、清除
在类中添加方法 def setup_class() 和 def teardown_class()
在定义了该方法 def setup_class() 和 def teardown_class() 的类中所有的用例执行前后只执行一次
3、模块级别初始化、清除,整个模块中所有类中的内容执行前后运行setup_module和teardown_module,必须设置全局方法 def setup_module() 和 def teardown_module()
示例代码如下:
# -*- coding:utf-8 -*-
# @Author: 喵酱
# @time: 2022 - 06 -29
# @File: test_cs_setup.py
import pytest
def setup_module(self):
print('setup_module环境初始化')
def teardown_module(self):
print('teardown_module环境清除')
class Test1:
def setup_class(self):
print('setup_class环境初始化')
def teardown_class(self):
print('teardown_class环境清除')
def setup_method(self):
print('setup_method环境初始化')
def teardown_method(self):
print('teardown_method环境清除')
def setup(self):
print('setup环境初始化')
def teardown(self):
print('teardown清理环境')
def test_1(self):
assert 1 == 1
def test_2(self):
assert 1 == 1
def test_3(self):
assert 1 == 1
打印:
Process finished with exit code 0
setup_module环境初始化
setup_class环境初始化
setup_method环境初始化
setup环境初始化
PASSED [ 33%]teardown清理环境
teardown_method环境清除
setup_method环境初始化
setup环境初始化
PASSED [ 66%]teardown清理环境
teardown_method环境清除
setup_method环境初始化
setup环境初始化
PASSED [100%]teardown清理环境
teardown_method环境清除
teardown_class环境清除
teardown_module环境清除
原文地址:
https://www.csdn.net/tags/MtjaQgxsNTM5MDItYmxvZwO0O0OO0O0O.html
边栏推荐
- Advanced use of the optional class
- PROJECT #1 - BUFFER POOL [CMU 15-445645]笔记
- 疫情下我离职一年,收入增长了10倍
- Laravel creates its own facade extension geoip to obtain country, region and city information according to IP
- wirehark数据分析与取证infiltration.pacapng
- mysql备份数据库linux
- 语音信号处理(二): 发声生理、听觉生理与听觉心理
- An in-depth analysis of the election mechanism in kubernetes
- 2022 PMP project management examination agile knowledge points (5)
- sql刷题595. 大的国家
猜你喜欢

Can you be a coder if you don't learn English well? Stop worrying and learn it first

Qt中使用QDomDocument和QDomnode来读取xml

疫情下我离职一年,收入增长了10倍

Leetcode 1385. 两个数组间的距离值

Intranet penetration (NC)

How can the local / park do a good job in industrial analysis?

优雅的改造短信业务模块,策略模式走起!

众昂矿业:萤石助力氟产业锂电建设发展

地方/园区如何做好产业分析?

NRM explanation
随机推荐
Weekly Postgres world news 2022w25
还天天熬夜加班做报表?其实你根本不懂如何高效做报表
深入解析kubernetes controller-runtime
基金的信息披露
基金的估值,费用,会计核算
laravel 关联模型 多态关系
众昂矿业:萤石助力氟产业锂电建设发展
剑指 Offer 38. 字符串的排列
R & D test time ratio, bug data analysis
5-2web application vulnerability scanning
Wireshark data analysis and forensics information pacapng
Basic use of Nacos configuration center
数据库-玩转数据-Pgsql 使用UUID做主键
Processing of error b6267342 reported by AIX small machine in production environment
Design of Distributed Message Oriented Middleware
疫情下我离职一年,收入增长了10倍
Summer rainbow comes for dinner
The client can connect to remote MySQL
字节云数据库未来方向的探索与实践
Inspiration collection · evaluation of creative writing software: flomo, obsidian memo, napkin, flowus