一、使用fixture装饰器来实现部分用例的前后置
参数解释以及组成
scope 表示的是被@pytest.fixture标记的方法的作用域,function(默认),class,module,package/session.
params:参数化(支持,list,tuple,字典列表[{},{},{}],字典元组) # autouse = True:自动执行,默认是False
ids:当使用params参数化时候,给每一个值设置一个变量名,意义不大
names :给表示的是被@pytest.fixture标记的方法取一个别名
写法:@pytest.fixture(scope=“”,params=“”,autouse=“”,ids=“”,name=“”)
import pytest
@pytest.fixture(scope=“function”,params=[‘成龙’,‘甄子丹’,‘小可爱’])
def my_fixture(request):
return request.param
# print(‘这是前置的方法’)
# yield
# print(‘这是后置’)
class Testxiaoshuai:
def test_01_xiaoshuai(self):
print(‘\n测试小三’)
def test_02_xiaoge(self):
print('\n测试小二')
class Testxiaoshuai