在pytest中使用yaml传参,yaml中的内容为- data_json1: { data_json: { "dataConllection": '{"dataBMR":1186,"dataBirthMonth":6,"dataBirthYear":2000,"dataBreakfastRNI":"325~458","dataDbz":"52","dataDbzRate":"0.16","dataDinnerRNI":"325~458","dataGender":"female","dataHeight":"160","dataId":"","dataLunchRNI":"459~585","dataRDI":1305,"dataSnacksRNI":"0~131","dataSportState":0,"dataTs":"173","dataTsRate":"0.53","dataUserId":"ac118362914749b7a57b01d925e35dad","dataUserWeightValue":"100.0","dataZf":"36","dataZfRate":"0.31","associatedModelsMapForJoinTable":{},"associatedModelsMapWithFK":{},"associatedModelsMapWithoutFK":{},"baseObjId":1,"fieldsToSetToDefault":null,"listToClearAssociatedFK":[],"listToClearSelfFK":[]}' } },怎么修改才能让这个只成为一个用例
时间: 2023-08-30 22:10:25 浏览: 69
你可以将 YAML 文件的内容修改为以下形式:
```yaml
- name: test_case_name
data_json: '{"dataBMR":1186,"dataBirthMonth":6,"dataBirthYear":2000,"dataBreakfastRNI":"325~458","dataDbz":"52","dataDbzRate":"0.16","dataDinnerRNI":"325~458","dataGender":"female","dataHeight":"160","dataId":"","dataLunchRNI":"459~585","dataRDI":1305,"dataSnacksRNI":"0~131","dataSportState":0,"dataTs":"173","dataTsRate":"0.53","dataUserId":"ac118362914749b7a57b01d925e35dad","dataUserWeightValue":"100.0","dataZf":"36","dataZfRate":"0.31","associatedModelsMapForJoinTable":{},"associatedModelsMapWithFK":{},"associatedModelsMapWithoutFK":{},"baseObjId":1,"fieldsToSetToDefault":null,"listToClearAssociatedFK":[],"listToClearSelfFK":[]}'
```
这样你就可以在 pytest 中使用 `data_json` 变量来引用该字符串了。此外,你还需要在 pytest 的测试函数中接收这个参数,例如:
```python
def test_my_function(data_json):
# 使用 data_json 参数
pass
```
阅读全文