# case.yaml
test_datas:
- "输入正确的用户名 1"
- username: test1
password: 123456
- expect_msg: success
- "输入错误的用户名"
- username: test2
password: 123456
- expect_msg: failed
- "输入正确的用户名 2"
- username: test3
password: 123456
- expect_msg: success
test_datas = [
("输入正确的用户名 1", {"username": "test1", "password": "123456"}, {"expect_msg": "success"}),
("输入错误的用户名", {"username": "test2", "password": "123456"}, {"expect_msg": "failed"}),
("输入正确的用户名 2", {"username": "test3", "password": "123456"}, {"expect_msg": "success"}),
]
import yaml
def load_yaml(file_path):
with open(file_path, encoding='utf-8') as f:
data = yaml.safe_load(f)
return data # 这里实在不知道怎么处理了😭,求大佬帮忙
if __name__ == '__main__':
load_yaml("case.yaml")
1
QingchuanZhang 2020-06-30 23:41:20 +08:00
```python3
def load_yaml(file_path): with open(file_path, encoding='utf-8') as f: data = yaml.safe_load(f) record_len = 3 for records in data.values(): res = [] for i in range(0, len(records), record_len): res.append(tuple(records[i:i + record_len])) return res ``` |
2
QingchuanZhang 2020-06-30 23:43:14 +08:00
@QingchuanZhang https://paste.ubuntu.com/p/HyQbk4NtTz/ 不太会写代码,见笑了
|
3
Cy86 2020-07-01 03:12:47 +08:00
test_datas:
- - "输入正确的用户名 1" - username: test1 password: 123456 - expect_msg: success - - "输入错误的用户名" - username: test2 password: 123456 - expect_msg: failed - - "输入正确的用户名 2" - username: test3 password: 123456 - expect_msg: success 我改成这样输出比较接近你要的格式, 但需要修改 YAML 格式 |