当前位置:   article > 正文

pytest.mark.parametrize参数化引用另一个模块py文件里的函数数据_pytest 引用另一个文件方法

pytest 引用另一个文件方法
#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"表示打印详细信息
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

打印结果:
============================= 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()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

#yaml文件 内容
#yamlFile.yaml
#- name: 张三
#school:

name: 张三,

lsd: lisi

  • name: x接口
    request:
    method: get
    url: https://www.bilibili.com/
    headers: “None”
    parame:
    useName: lili
    password: li12345
    ID: 12
    assert: “None”
  • name: x接口2
    request:
    method: post
    url: https://www.bilibili.com/api
    headers: “None”
    parame:
    useName: lili
    password: li12345
    ID: 12
    assert: “None”
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/143738
推荐阅读
相关标签
  

闽ICP备14008679号