关于python:0208-Python库yaml

2次阅读

共计 392 个字符,预计需要花费 1 分钟才能阅读完成。

yaml 库装置:

pip install yaml 

Python 应用第三方库之【yaml】

yaml 语法:

YAML 入门教程

理论利用:

import yaml


def get_data(path, key):
    with open(path, encoding="utf-8") as file:
        data = yaml.safe_load(file)
        return data[key]


# 在测试用例参数化时传递数据
@pytest.mark.parametrize("a, b, expect",
                         get_data(yaml_path, "add"),
                         ids=["整数", "小数", "大整数"])
def test_add(self, a, b, expect, setup_fixture):
    """测试加法正向用例"""
    result = setup_fixture.add_func(a, b)
    assert abs(result - expect) < 0.01
正文完
 0