转载https://www.cnblogs.com/mujinxi/p/15302167.html

.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.加上判断忽略掉注释和空行,就不会报错了(源代码路径:httprunner-->loader.py)

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")
posted on 2021-11-12 14:04  李大幽默  阅读(104)  评论(0编辑  收藏  举报