总结:
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")