接口自动化框架之python pytest-setup\teardown(四)

一、简介

主要是为了做资源冗余处理,比如说再setup里连接数据库或者打开一些文件之类的,在用完后teardown再释放掉

二、类里边或者函数运行在调用方法前后

一般常用的是这两个作用域方式

import pytest

def setup():
    print('setup')
def teardown():
    print('teardown')

def test_01():
    print('01')

def test_02():
    print('02')

class TestCase:
    def setup(self):
        print('setup')

    def teardown(self):
        print('teardown')

    def test_one(self):
        print('one')

    def test_two(self):
        print('two')

if __name__ == '__main__':
    pytest.main(['-s','-v','test_setup.py'])

三、其他作用域使用介绍

  • 方法/函数级别(setup/teardown)
  • 函数级(setup_function/teardown_function)
  • 方法级(setup_method/teardown_method)
  • 类级(setup_class/teardown_class)
  • 模块级(setup_module/teardown_module)

这里不为大家一一介绍了,后续几种大家可以自行敲写做感受

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值