赞
踩
#readYaml_list.py
import pytest
# from pytest.testPrame import readYaml
# ff=readYaml.readYaml02()
# print(ff)
from readYaml import readYaml02
class TestPrame2:
@pytest.mark.parametrize("APIname",readYaml02())
def test_prame01(self,APIname):#def函数和@pytest.mark.parametrize之间不能隔开,空行/注释代码都不行,隔开就不打印内容
print("APIname打印",APIname)
print("APIname打印name******", APIname['name'])
print("****APIname打印'parame'", APIname['request']['parame'])
#print(name)
if __name__ == '__main__':
pytest.main(["-vs"])#"-vs"表示打印详细信息
打印结果:
============================= test session starts =============================
platform win32 – Python 3.8.1, pytest-7.2.1, pluggy-0.13.1
rootdir: E:\Python3.8\project\pytest\testPramecollected 2 items
readYaml_list.py .APIname打印 {‘name’: ‘x接口’, ‘request’: {‘method’: ‘get’, ‘url’: ‘https://www.bilibili.com/’, ‘headers’: ‘None’, ‘parame’: {‘useName’: ‘lili’, ‘password’: ‘li12345’, ‘ID’: 12}}, ‘assert’: ‘None’}
APIname打印name****** x接口
APIname打印’parame’ {‘useName’: ‘lili’, ‘password’: ‘li12345’, ‘ID’: 12}
.APIname打印 {‘name’: ‘x接口2’, ‘request’: {‘method’: ‘post’, ‘url’: ‘https://www.bilibili.com/api’, ‘headers’: ‘None’, ‘parame’: {‘useName’: ‘lili’, ‘password’: ‘li12345’, ‘ID’: 12}}, ‘assert’: ‘None’}
APIname打印name** x接口2
****APIname打印’parame’ {‘useName’: ‘lili’, ‘password’: ‘li12345’, ‘ID’: 12}
[100%]
============================== 2 passed in 0.17s ==============================
Process finished with exit code 0
#readYaml.py
import yaml
def readYaml02():
#f=open("yamlFile.yaml",encoding='utf-8',mode='r')
with open("yamlFile", encoding='utf-8', mode='r') as f:
vale=yaml.load(stream=f, Loader=yaml.FullLoader)
print(vale)
return vale
readYaml02()
#yaml文件 内容
#yamlFile.yaml
#- name: 张三
#school:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。