Pytest学习-yaml+parametrize使用

Pytest学习-yaml+parametrize使用

原创

我的事说来话长博主文章分类:Pytest ©著作权

文章标签 pytest 文章分类 Python 后端开发

©著作权归作者所有:来自51CTO博客作者我的事说来话长的原创作品,请联系作者获取转载授权,否则将追究法律责任

一、读取yaml(关键点在于文件的路径)

1、单参数版,多参数版

#!/usr/bin/env python# -*- coding: UTF-8 -*-"""@Project :Pytest @File :read_data.py@IDE  :PyCharm @Author :zhou@Date :2022/8/6 19:05 """import osimport yamlpath = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "config", "data.yaml")def read_data():    # 获取文件    f = open(path, encoding="utf-8")    # 读取文件内容    data = yaml.safe_load(f)    return dataget_data = read_data()print(get_data)

二、parametrize使用yaml文件中的数据

单参数版@pytest.mark.parametrize("name", get_data['person'])def test_parametrize_02(name):    print(name)# 多参数版@pytest.mark.parametrize("name,word", get_data['person'])def test_parametrize_02(name,word):    print(f'{name}'的口头禅是{word}')

Pytest学习-yaml+parametrize使用
  • 收藏
  • 评论
  • *举报

上一篇:Pytest学习-读取YAML文件

下一篇:Pytest学习-yaml+parametrize接口实战

Original: https://blog.51cto.com/u_15626734/5551234
Author: 我的事说来话长
Title: Pytest学习-yaml+parametrize使用

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/504411/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球