1、fixture返回值
1、获取被调用函数返回值(1个返回值)
import pytest
@pytest.fixture(scope='function')
def login():
accesstoken = '875sdfdhlghf'
return accesstoken
def test_sum(login):
token = login
print(token)
# 执行结果:
# 875sdfdhlghf
# .
if __name__ =="__main__":
pytest.main(['test_example.py','-s'])
2、获取被调用函数返回值(多个返回值)
import pytest
@pytest.fixture(scope='function')
def login():
accesstoken = '875sdfdhlghf'
customerguid = '0242ac11000d'
return accesstoken,customerguid
def test_sum(login):
token = login[0]
guid = login[1]
print(token)
print(guid)
# 执行结果:
# 875sdfdhlghf
# 0242ac11000d
# .
if __name__ =="__main__":
pytest.main(['test_sample.py', '-s'])
2、单个用例调用多个函数
import pytest
@pytest.fixture(scope='function')
def login():
print('登录')
@pytest.fixture(scope='function')
def conn():
print('连接数据库')
def test_1(login,conn):
print('测试用例1')
def test_2():
print('测试用例2')
if __name__ =="__main__":
pytest.main(['test_sample.py','-s'])
# 执行结果:
# test_sample.py
# 登录
# 连接数据库
# 测试用例1
# .
# 测试用例2
# .
版权声明:本文为weixin_44801980原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。