当前位置:网站首页>Pytest initializing and cleaning up the environment
Pytest initializing and cleaning up the environment
2022-06-29 23:18:00 【Proud cat sauce】
One 、setup and teardown The way
1、 Method level initialization 、 eliminate , Each method is executed once before and after it runs
setup and teardown,setup_method,teardown_method
2、 Class level initialization 、 eliminate
Add methods to the class def setup_class() and def teardown_class()
After defining the method def setup_class() and def teardown_class() All use cases in the class of are executed only once before and after execution
3、 Module level initialization 、 eliminate , The contents of all classes in the whole module run before and after execution setup_module and teardown_module, The global method must be set def setup_module() and def teardown_module()
The sample code is as follows :
# -*- coding:utf-8 -*-
# @Author: Meow sauce
# @time: 2022 - 06 -29
# @File: test_cs_setup.py
import pytest
def setup_module(self):
print('setup_module Environment initialization ')
def teardown_module(self):
print('teardown_module Environmental cleanup ')
class Test1:
def setup_class(self):
print('setup_class Environment initialization ')
def teardown_class(self):
print('teardown_class Environmental cleanup ')
def setup_method(self):
print('setup_method Environment initialization ')
def teardown_method(self):
print('teardown_method Environmental cleanup ')
def setup(self):
print('setup Environment initialization ')
def teardown(self):
print('teardown Clean up the environment ')
def test_1(self):
assert 1 == 1
def test_2(self):
assert 1 == 1
def test_3(self):
assert 1 == 1
Print :
Process finished with exit code 0
setup_module Environment initialization
setup_class Environment initialization
setup_method Environment initialization
setup Environment initialization
PASSED [ 33%]teardown Clean up the environment
teardown_method Environmental cleanup
setup_method Environment initialization
setup Environment initialization
PASSED [ 66%]teardown Clean up the environment
teardown_method Environmental cleanup
setup_method Environment initialization
setup Environment initialization
PASSED [100%]teardown Clean up the environment
teardown_method Environmental cleanup
teardown_class Environmental cleanup
teardown_module Environmental cleanup
Original address :
https://www.csdn.net/tags/MtjaQgxsNTM5MDItYmxvZwO0O0OO0O0O.html
边栏推荐
- error: C2665: “QMessageBox::critical”: 4 个重载中没有一个可以转换所有参数类型
- STM32基础知识点
- Inspiration collection · evaluation of creative writing software: flomo, obsidian memo, napkin, flowus
- Mysql database: partition
- Qt5.14.2 error connecting to the MySQL database of Ubuntu 20.04
- An in-depth analysis of the election mechanism in kubernetes
- Is it safe to open an account on the flush? Where to apply for opening an account
- How ZABBIX 5.0 adds esxi6.7 to monitoring
- What if MySQL fails to store emoticons
- 十大券商:“推土机行情”再现
猜你喜欢
Evolution from stand-alone to distributed database storage system

记一次排查线上MySQL死锁过程,不能只会curd,还要知道加锁原理

Basic use of Nacos configuration center

论文阅读《Large-Scale Direct SLAM with Stereo Cameras》

InfluxDB时序数据库系统
![Project 1 - buffer pool [cmu 15-445645] notes](/img/33/304e3e78f62b156d0863a41d243679.png)
Project 1 - buffer pool [cmu 15-445645] notes

VS无法定位程序输入点于动态链接库

Node data collection and remote flooding transmission of label information
![PROJECT #1 - BUFFER POOL [CMU 15-445645]笔记](/img/33/304e3e78f62b156d0863a41d243679.png)
PROJECT #1 - BUFFER POOL [CMU 15-445645]笔记

Hezhou air32f103cbt6 development board hands-on Report
随机推荐
STM32 basic knowledge points
C language tutorial – -6 loop statement
Qdomdocument and qdomnode are used in QT to read XML
十大券商:“推土机行情”再现
软件测试 接口测试 Jmeter 5.5 安装教程
动态代理的实现原理
Phpspreadsheet reading and writing Excel files
CE第二次作业
VS无法定位程序输入点于动态链接库
Node data collection and remote flooding transmission of label information
JS function related review
Static keyword continuation, inheritance, rewrite, polymorphism
動態代理的實現原理
Vs cannot locate program input point to DLL
Day9 - user registration and login
软件测试 接口测试 Postman测试工具 接口测试的流程 执行接口测试 接口关联 环境变量和全局变量 内置动态参数以及自动有的动态参数
How to solve the problem that the computer time is not automatically updated after proofreading
语音信号处理(二): 发声生理、听觉生理与听觉心理
Laravel creates its own facade extension geoip to obtain country, region and city information according to IP
Sword finger offer 38 Arrangement of strings