6.pytest_fixture之yield实现teardown

上一篇讲到fixture通过scope参数控制setup级别,既然有setup作为用例之前前的操作,用例执行完之后那肯定也有teardown操作。
这里用到fixtureteardown操作并不是独立的函数,用yield关键字呼唤teardown操作;

scope=“module”

1.fixture参数scope="module"module作用是整个.py文件都会生效,用例调用时,参数写上函数名称就行;

import pytest

@pytest.fixture(scope="module")
def login():
    print("=================开始登陆login====================")
def test_01(login):
    print("====================test_01================")
def test_02():
    print("====================test_02================")

def test_03(login):
    print("====================test_03================")


if __name__ == "__main__":
    pytest.main(["-s","test_fix3.py"])

运行结果:

test_fix3.py::test_01 =================开始登陆login====================
PASSED                                             [ 33%]====================test_01================

test_fix3.py::test_02 PASSED                                             [ 66%]====================test_02================

test_fix3.py::test_03 PASSED                                             [100%]==
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值