def c1():
logfile = open("D:\myfile.txt", 'r')
for num1, line in enumerate(logfile):
if "request=100" in line:
print num1
return True
return False
def c2():
logfile = open("D:\myfile.txt", 'r')
for num2, line in enumerate(logfile):
if "response=200" in line:
print num2
return True
return False
if c1() == True and c2() == True:
print "Test Case Passed"
else:
print "Test Case Failed"
在上面的代码中,不存在检查行号以使request=100和response=200将落在同一行中。我需要的。
另外,我想打印结果为“通过”只有在以下条件满足。。。
^{pr2}$
如果出现以下情况,则结果为“失败”:- if any one line which consists of "request=200" and "response=200"
- if any one line which consists of "request=100" and "response=100"
- or any case in which no line should have apart from "request=100" and "response=200"
假设“myfile”包含以下数据:request=100 XXXXXXXXXXXXXXXXXXXXXXXXXXXX \n
XXXXXXXXXXXXXXXX response=200 XXXXXXXXX \n
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \n
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \n
XXXX request=100 XXXXX response=200 XXXXXXXXXXX \n
XXXXXXX request=200 XXXXXX response=100 XXXXXXX \n
XXXXXXXX request=100 XXXX response=100" \n
在上面的文件中,结果是失败的,因为请求和响应的值与所需的值不同。只有第5行有正确的值,因此结果失败。