目录:导读
前言
fixture说明
fixture可以让我们自定义测试用例的前置条件,fixture可作为共享数据使用
1、fixture可以当做参数传入
import pytest
@pytest.fixture()
def test1():
print('\n开始执行function')
def test_a(test1): #传函数名
print('---用例a执行---')
class TestCase:
def test_b(self, test1):
print('---用例b执行')
if __name__ == '__main__':
pytest.main(["-s", "-v", "-q","test_fixture03.py"])
运行结果:
2、使用装饰器@pytest.mark.usefixtures()修饰需要运行的用例
import pytest
@pytest.fixture()
def test1():
print('\n开始执行function')
@pytest.mark.usefixtures('test1') #关键字,可以传多个
def test_a():
print('---用例a执行---')
@pytest.mark.usefixtures('test1')
class TestCase: