.env
testenv=xxxxx
1.当文件内包含注释或空行时,抛出异常 httprunner.exceptions.FileFormatError: .env format error
原因是源代码中没有对空行和 # 号做处理,代码片段 (loader - 130):
with open(dot_env_path, mode="rb") as fp:
for line in fp:
# maxsplit=1
if b"=" in line:
variable, value = line.split(b"=", 1)
elif b":" in line:
variable, value = line.split(b":", 1)
else:
raise exceptions.FileFormatError(".env format error")
2.加上判断忽略掉注释和空行,就不会报错了
with open(dot_env_path, mode="rb") as fp:
for line in fp:
# maxsplit=1
line = line.strip()
if not len(line) or line.startswith(b"#"):
continue
if b"=" in line:
variable, value = line.split(b"=", 1)
elif b":" in line:
variable, value = line.split(b":", 1)
else:
raise exceptions.FileFormatError(".env format error")