python csv 数据切割定制jmeter数据
原创
©著作权归作者所有:来自51CTO博客作者wx5b6d6c951e615的原创作品,请联系作者获取转载授权,否则将追究法律责任
需求压测随机抽取10w数据中自定义区间的指定数量数据进行压测:
jmeter csv/txt配置:
需要获取{data: [${myList}] } jmeter需要数据类型
获取展读取csv数据展示{ data:
[
"cfcd208495d565ef66e7dff9f98764da", "c4ca4238a0b923820dcc509a6f75849b", "c81e728d9d4c2f636f067f89cc14862c"
]
}
import hmac
import base64
from hashlib import sha1
import random
def test_get(index_start:int,n,path):
with open(path, 'r') as f:
lines = f.readlines()
lines_data = [i.strip() for i in lines]
if n%1000==0:
numbers=int(n/1000)
datas=[]
for i in range(numbers):
data=lines_data[index_start:index_start+1000]
datas.extend(data)
print("数据拼接长度{}".format(len(datas)))
dt=["{}".format(i) for i in datas]
return dt
else:
numbers=int(n/1000)
remain=n%1000
datas = []
for i in range(numbers):
data = lines_data[index_start:index_start + 1000]
datas.extend(data)
seed=random.randint(index_start,index_start+100)
datas.extend(lines_data[index_start+seed:index_start+seed
+remain])
print("数据拼接长度{}".format(len(datas)))
dt = ["{}".format(i) for i in datas]
return dt
def write_result(index,numbers,path_csv):
datas=test_get(index_start=index,n=numbers,path=path_csv)
st=''
for i in datas:
st +='"{}", '.format(i)
with open('./result.txt', 'w') as f:
f.write('{}'.format(st.strip().strip(',')))
"""
def hash_mac(app_secret:str,msg:str):
hmac_code = hmac.new(app_secret.encode(), msg.encode(), sha1).digest()
return base64.b64encode(hmac_code).decode()
"""
if __name__ == '__main__':
write_result(0, 1000, path_csv=r"D:\workspace\DS_4.csv")
生成数据csv/txt数据格式: