读取当前文件夹路径
import os
get_dir=os.path.dirname(os.path.abspath(__file__))
if __name__ == '__main__':
print(get_dir)
CSV文件的读取
name,password,expect
"",admin,'帐号或密码错误'
admin,"",'帐号或密码不能为空'
"","",'帐号或密码不能为空'
frwf,admin,'帐号或密码错误'
admin,fewfe,'帐号或密码错误'
admin,admin
lisi,123456
wangwu,zelin123
import csv
import os
from Project.csv_get_config import get_dir
def read_error_csv():
filepath=os.path.join(get_dir,'Data_Layer/login.csv')
with open(filepath,mode='r',encoding='utf-8') as fp:
get_result=csv.reader(fp)
return [i for i in list(get_result)[1:6]]
def read_right_csv():
filepath=os.path.join(get_dir,'Data_Layer/login.csv')
with open(filepath,mode='r',encoding='utf-8') as fp:
get_result=csv.reader(fp)
return [i for i in list(get_result)[6:]]
print(read_error_csv())
print(read_right_csv())
YAML文件的读取
test_login1:
- {"states": 1, "message": "登录成功", "username": "lisi", "password": "123456"}
test_login2:
- {"states": 0, "message": "账号在数据库中不存在", "username": ""}
test_login3:
- {'states': 0, 'message': '密码输入错误', 'password': '12345'}
import yaml
def logintest():
with open(r'D:\Project\expect.yaml',mode='r',encoding='utf-8') as fp:
get_result=yaml.load(fp,Loader=yaml.SafeLoader)
return get_result