In the below code, I need to give more than one case name. For example: Giving "login" and "deploy" casenames if j["case_name"] == "login" and "deploy" And then change enabled value for both to False Is it possible ? or there is some other way where I can change enabled value to false for more than one casename.
import yaml
y = yaml.safe_load(open("data.yaml", "r"))
for i in y["tiers"]:
for j in i["testcases"]:
if j["case_name"] == "login":
j["enabled"] = False
yaml.dump(y, open("new_data.yaml", "x"))
Below is the content from YAML file
tiers:
-
name: testing
order: 1
description: ''
testcases:
-
case_name: deploy
project_name: project
enabled: true
criteria: 100
blocking: false
clean_flag: false
description: ''
run:
name: 'deploy'
-
case_name: login
project_name: project
enabled: true
criteria: 100
blocking: false
clean_flag: false
description: ''
run:
name: 'login'
I am not completely sure this is what you want but it sounds like you want to do
for i in y["tiers"]:
for j in i["testcases"]:
if j["case_name"] in ["login", "deploy"]:
j["enabled"] = False
I advise to describe what you want to do in prose instead of giving misleading pseudocode since a logical and does not make any sense in this case – you most likely want a logical or, which is what this code implements.