Pytest Fixture与作用阈

总结:

1、单元测试中有很多测试用例,用例中有很多重复的动作,这也动作可以用fixture共享

2、fixture有作用域包括class、module、package、session,每个作用域覆盖范围不同,举例:如果一个文件中有两个类测试单元,这两个类分别在开头和结束时载入夹具

from multiprocessing import cpu_count
import pytest

@pytest.fixture(autouse = True, scope = "module")
# @pytest.fixture(autouse = True, scope = "class")
def base_dirver():
    str_ = "dirver run"
    print(f'{str_} ok')
    yield str_
    print("shut down dirver")

class TestclientProess:
    def test_login(self):
        print("test_login is ok")

    def test_register(self):
        print("test_register is ok")

class TestOptProess:
    def test_add_goods(self):
        print("test_add_goods is ok")

    def test_delete_goods(self):
        print("test_delete_goods is ok")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值