处理项目路径的编写思路(handle_path模块)
初衷:代码维护的方便性
第一步:导入os模块
提供了多数操作系统的功能接口函数
import os
第二步:获取项目根目录
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
描述:
os.path.dirname:获取父级目录
os.path.abspath(__ file__):获取的当前执行脚本的完整路径
根据实际的项目结构来获取根目录
第三步:获取项目根目录
配置各文件的路径
# 测试用例的目录路径
CASE_DIR = os.path.join(BASE_DIR,"testcase")
# 测试报告的目录路径
REPORT_DIR = os.path.join(BASE_DIR,"reports")
# 日志目录的项目路径
LOG_DIR = os.path.join(BASE_DIR,"logs")
# 用例数据的项目路径
DATA_DIR = os.path.join(BASE_DIR,"data")
# 配置文件目录的路径
CONF_DIR = os.path.join(BASE_DIR,"conf")
描述:os.path.join(),路径拼接