Last active
July 14, 2016 01:55
-
-
Save quxiaowei/5440de7c9e2e9b835e5b6225b040a491 to your computer and use it in GitHub Desktop.
和其他接口测试写的脚本,暂存着
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from datetime import datetime | |
def timer(file): | |
def wrapper(func): | |
def wrapper(*argv): | |
d1 = datetime.now() | |
res = func(*argv) | |
d2 = datetime.now() | |
file.write('duration:{0.seconds}s {0.microseconds}ms\n'.format(d2-d1)) | |
return res | |
return wrapper | |
return wrapper | |
with open('D:\\test.txt') as f: | |
with open('D:\\test_result.txt', 'w+') as d: | |
def get(*argv): | |
url = 'http://hostname/{}/{}/{}'.format(*argv) # !url format | |
@timer(file=d) | |
def get_r(url): | |
return requests.get(url) | |
return get_r(url).text #'restul:{result}\terrorcode:{errorCode}\tmessage:{errorMessage}'.format(**(requests.get(url).json()[0])) | |
for line in f.readlines(): | |
param = line.strip().split('\t') # !saparator | |
result1 = get(*(param[:-1])) | |
d.write( '\t'.join( param + [result1, '\n'] )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment