一、读取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 o
一、读取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 os
import yaml
path = 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 data
get_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}')