other_func.py
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# @Time :2019/11/26 11:23
# @Author :dengyuting
# @File :login_func.py
import json
##每次执行自动化测试前,清空该文件,该文件用于批量支付时传orderids
def setup_hook_clean_orderid():
try:
with open('config/orderid.csv', 'w') as f:
f.seek(0)
f.truncate()
except Exception as e:
print('清空失败', e)
def teardown_hook_get_orderid(response):
if response.status_code == 200:
jsondata = json.loads(response.text)
orderid =jsondata['data']['id']
try:
# 保存token到文件
with open('config/orderid.csv','a+') as f:
f.write(str(orderid)+',')
print('写入成功,orderid:{}'.format(orderid))
f.close()
except Exception as e:
print('写入失败', e)
return orderid
def get_orderids():
try:
with open('config/orderid.csv','r') as f:
orderids = f.read()
print('读取orderids成功:{}'.format(orderids))
f.close()
except Exception as e:
print('读取失败', e)
orderid = orderids.split(',')
orderid.pop(-1)
return orderid