当前位置:网站首页>Pytest interface automation test framework | setup and teardown functions of pytest
Pytest interface automation test framework | setup and teardown functions of pytest
2022-07-26 11:57:00 【COCOgsta】
Video source :B standing 《 Risking your life to upload !pytest Interface automation test framework ( From basic theory to project practice and secondary development ) Teaching video 【 software test 】》
Organize the teacher's course content and test notes while studying , And share it with you , Infringement is deleted , Thank you for your support !
Attach summary sticker :pytest Interface automation test framework | Summary _COCOgsta The blog of -CSDN Blog
test_setup01.py
import pytest
def multiply(a, b):
return a * b
"""
The first time :setup_module/teardown_module: In the current file , Before and after the execution of all test cases
The second batch :setup_function/teardown_function: Execute before and after each test function
The third batch :setup/teardown: Execute before and after each test function , this 2 Methods also apply to class methods
PS: The definition order of methods has been adjusted , It is also implemented according to the established rules
"""
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("teardown_function------------------------------>")
def setup():
print("setup--->")
def teardown():
print("teardown--->")
# The test case
def test_mul_01():
print('test_3_4')
assert multiply(3,4) == 12
def test_mul_02():
print('test_6_8')
assert multiply(6,8) == 48main.py, Actual execution setup and teardown No printing
import pytest
if __name__ == '__main__':
pytest.main(["-s", "test_setup01.py"])test_setup02.py
import pytest
# Function function
def multiply(a, b):
return a * b
"""
pytest It supports the use of test classes , Must be “Test” start , Pay attention to the capitals
"""
class TestMultiply:
# =======fixtures=======
"""
The first time :setup_ class / teardown_ class:
# Execute at the beginning and end of the current test class .
The second batch :setup_ method / teardown_ method:
# Execute at the beginning and end of each test method .
The third batch :setup / teardown:
# Execute at the beginning and end of each test method , It can also act on test functions
PS: The execution sequence is in batch order , Even if the method position is changed , Is the same
"""
@classmethod
def setup_class(cls):
print("setup_class==============>")
@classmethod
def 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---->")
# ======= The test case ===========
def test_numbers_5_6(self):
print('test_numbers_5_6')
assert multiply(5,6) == 30
def test_strings_b_2(self):
print('test_strings_b_2')
assert multiply('b', 2) == "bb"main.py, In actual operation, there is no printing setup and teardown
import pytest
if __name__ == '__main__':
pytest.main(["-s", "test_setup02.py"])边栏推荐
- Which is faster to open a file with an absolute path than to query a database?
- 程序员培训学习后好找工作吗?
- Exploration on cache design optimization of community like business
- Understanding useref is enough
- 请问下有人知道FlinkSQL 的 Retrack 在哪里可以指定吗? 网上资料只看到API 代码设
- [countdown 10 days] Tencent cloud audio and video special is about to meet, and the thousand yuan prize is waiting for you!
- [communication principle] Chapter 1 -- Introduction
- How did the $50000 annual salary run out
- Outsourcing for four years, abandoned
- Metauniverse gamefi chain game system development NFT Technology
猜你喜欢

基于 Flink CDC 实现海量数据的实时同步和转换

Exploration on cache design optimization of community like business

。。。。。。

Understand the string class

An online duplicate of a hidden bug

3.1 创建菜单与游戏页面——上

Live broadcast preview at 19:30 on July 27: harmonyos3 and Huawei's full scene new product launch

Yuancosmos daily | yuancosmos social app "Party Island" product off the shelves; Guangzhou Nansha yuanuniverse industrial agglomeration zone was unveiled; The inter ministerial joint conference system

线上一个隐匿 Bug 的复盘

Esp8266 Arduino programming example - development environment construction (based on Arduino IDE)
随机推荐
10 reduce common "tricks"
JSJ-3/AC220V时间继电器
Understanding useref is enough
Redis实现Single单点登入--系统框架搭建(一)
元宇宙日报|元宇宙社交 App“派对岛”产品下架;广州南沙元宇宙产业集聚区揭牌;数字经济发展部际联席会议制度推出
Didi was fined 8billion! The era of making money from user data is over
了解string类
pytest接口自动化测试框架 | pytest的setup和teardown函数
The latest heart-shaped puzzle applet source code + with flow master
[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)
Question and answer No. 48: geek appointment - construction path of observable system
Mlx90640 infrared thermal imager temperature sensor module development notes (6)
Pytest interface automated test framework | fixture call fixture
面试官:如何处理高并发?
pytest接口自动化测试框架 | 使用装饰器修饰需要运行的用例
pytest接口自动化测试框架 | 通过标记表达式执行用例
大量if else判断如何优化?@Valib详解
浅谈Web Vitals
系统调用捕获和分析—修改内核方法添加系统调用
。。。。。。