当前位置: 首页 > 后端技术 > Python

02-08Python库-yaml

时间:2023-03-26 18:54:21 Python

yaml库安装:pipinstallyamlPython使用第三方库[yaml]yaml语法:YAML入门教程实际应用:importyamldefget_data(path,key):withopen(path,encoding="utf-8")asfile:data=yaml.safe_load(file)returndata[key]#测试用例参数化时传数据@pytest.mark.parametrize("a,b,expect",get_data(yaml_path,"add"),ids=["Integer","Decimal","BigInteger"])deftest_add(self,a,b,expect,setup_fixture):"""测试加法的正例"""result=setup_fixture.add_func(a,b)assertabs(result-expect)<0.01