【发布时间】:2019-01-12 08:33:20
【问题描述】:
我有rootFile = root.json文件,内容是
{
"tests":[
{
"test":"test1",
"url":"url1"
},
{
"test":"test2",
"url":"url2"
},
{
"test":"test3",
"url":"url3"
}
]
}
我有一个 python 函数,我要给它运行字符串参数
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)
当我的参数是 root.json 文件中存在的“test1 test2 test3”时,我得到这样的响应
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
但是当我给出不存在的参数时,输出是正确的。例如
Test test4 Doesn't exist
Test test5 Doesn't exist
Test test6 Doesn't exist
Test test7 Doesn't exist
无法理解为什么它实际存在时发送却不存在
【问题讨论】: