02-08 Python库-yaml
yaml库安装:
pip install 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
阅读 553
机智的测试生活
双非大龄青年,转行测试工程师。 分享测试工程师的职业经验, 提供付费转行咨询
0 条评论
得票最新