I have rootFile = root.json file which content is
{
"tests":[
{
"test":"test1",
"url":"url1"
},
{
"test":"test2",
"url":"url2"
},
{
"test":"test3",
"url":"url3"
}
]
}
and I have python function to which I am giving string params to run
def check(params):
runId=time.strftime("%Y%m%d-%H%M%S")
outputFile=Path(""+runId+".txt")
with open (rootFile) as rj:
data=json.load(rj)
for param in params:
for t in data['tests']:
if t['test'] == param:
urlToUse=t['url']
testrun(param, urlToUse, runId)
else:
nonExistingTest="Test "+param+" Doesn't exist \n"
if not outputFile.exists():
with open(outputFile,"a") as noSuchTest:
noSuchTest.write("Test "+param+" Doesn't exist \n")
elif not nonExistingTest in open(outputFile).read():
with open(outputFile,"a") as noSuchTest:
noSuchTest.write("Test "+param+" Doesn't exist \n")
with open(outputFile,"r") as pf:
message=pf.read()
slackResponse(message)
when my params is "test1 test2 test3" which exist in root.json file I am getting such response
Test test1 passed #this response comes from testrun() function
Test test1 Doesn't exist
Test test2 Doesn't exist
Test test2 passed #this response comes from testrun() function
Test test3 Doesn't exist
Test test3 passed #this response comes from testrun() function
But when I am giving non existing params the output is correct. e.g
Test test4 Doesn't exist
Test test5 Doesn't exist
Test test6 Doesn't exist
Test test7 Doesn't exist
Can't understand why it's sending doesn't exist when it's actually exists