python自动化接口测试里面经常用到的两个os.path方法
os.path.split(path ) : 把路径分割成 dirname(路径名) 和 basename(文件名),返回一个元组;
os.path.realpath(path):获取path的绝对路径;
os.path.realpath(__file__):获取realpath方法所在脚本的绝对路径
举例如下:
path = os.path.split(os.path.realpath(__file__))[0]
这里os.path.realpath(__file__) 返回当前脚本的绝对路径(比如是C:/users/automation/test.py);
os.path.split( ):将上面得到的绝对路径进行分割得到一个元组['C:/users/automation/', 'test.py']
在后面加上一个[0],即得到了‘C:/users/automation/’