我有一个行为步骤,它调用另一个 python 类中的方法,如下所示
@when('we query for a specific resource')
def step_impl(context):
context.resource='myresource'
jsonutil=JSONUtil.JSONUtil()
response=jsonutil.parseJSON(context.resource)
assert True
JSONUtil类中的parsejson方法如下
def parseJSON(self,resource):
url= "http://"+data.test.engine_url+'/api/v1/policies?resource='+resource
response=requests.get(url)
time.sleep(5)
json_data = json.loads(response.text)
#time.sleep(5)
#print(json_data)
x=[1,2,3]
for i in x:
print("%d" % i)
#for json_obj in json_data:
# if 'statements' in json_obj:
# print(json_obj['statements'][0]['resource'][0])
return response
执行此步骤时。我得到以下输出
1
2
<<Note that 3 does not get printed>>
但是当通过以下方式调用 parsejson 方法时
J=JSONUtil()
J.parseJSON('myJSON')
我得到以下输出
1
2
3
关于为什么使用行为调用代码时执行for循环n-1次的任何原因/指针?