如何用python编写yaml文件测试用例

oknwwptz  于 2023-03-20  发布在  Python
关注(0)|答案(1)|浏览(152)

有人能帮我用python写YAML文件的测试用例吗?
config.yaml
环境:发展

AthenaCred:
  AthenaDatabaseName: dap_cred
  AthenaTblName: athena_prod
  AwsSecretKey:  null
  AwsAccessKeyId: null
  S3StagingDir: 's3://aws-athena-query-results/'
  RegionName: 'us-east-1'

加载规则.yaml

Insert:
  - compute: 25:adobe:redshift
    entity: marketing
    group: '87:count'
    name: Test rule 1
    product: adobe
    query: SELECT count(*) "count" from public.dual
  - compute: 25:adobe:redshift
    entity: marketing
    group: '0:default'
    name: Test rule 2
    product: adobe
    query: SELECT count(*) from public.dual

Delete:
  rule_id:
    - '107:test'
    - '2:test'
f0ofjuux

f0ofjuux1#

单程

import sys
    import load_rule.yaml

    yaml_str = """\
    Get_Request:
      alias : 'amway1'
      session_url : 'url2'

    Post_Request:
      alias : 'amway2'
      session_url : 'url2'

    yaml = load_rule.yaml.YAML()
    try:
        data = yaml.load(yaml_str)
    except Exception as e:
        print(e)

另一种方式

import yaml

file_name = 'load_rule.yml'

with open(file_name) as infile:
    data = yaml.load(infile)

person = data['Person']
person['name'] = input('What is your name? ')
person['age'] = int(input('What is your age? '))
person['nationality'] = input('What is your nationality? ')
person['footed'] = input('What foot? ')
person['position'] = input('What is your position? ')

with open(file_name, 'w') as outfile:
    yaml.dump(data, stream=outfile, default_flow_style=False, indent=3)

在这里你可以根据你需要修改python代码,在python中打开yaml文件,将数据保存到数组中,进行对象查询并执行测试任务。

相关问题