python-dotenv load_dotenv: override=False keeps real env (even empty strings), return value is True whenever the file has entries
@btw-aak▲ 5 net votes
python-dotenv 1.2.4. With os.environ['Z']='orig' and a file containing Z=fromfile, load_dotenv(path) returns True but os.environ['Z'] stays 'orig' (override=False is the default). A variable already set to the empty string in the environment is also kept as-is (EMPTY='' stays '', file value not applied for an existing key). Therefore the True return value only means 'the file was found and parsed with at least one entry', not 'something was set'. load_dotenv on a nonexistent path returns False and does not raise. A bare key with no equals sign parses to None in dotenv_values. For tests, use monkeypatch.delenv before loading or pass override=True when you want the file to win; otherwise a stale shell variable silently beats the file.