Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,19 @@ def set_as_environment_variables(self) -> bool:
"""
Load the current dotenv as system environment variable.
"""
if not self.dict():
values = self.dict()
if not values:
return False

for k, v in self.dict().items():
set_variables = False
for k, v in values.items():
if k in os.environ and not self.override:
continue
if v is not None:
os.environ[k] = v
set_variables = True

return True
return set_variables

def get(self, key: str) -> Optional[str]:
""" """
Expand Down
10 changes: 10 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,16 @@ def test_load_dotenv_existing_file(dotenv_path):
assert os.environ == {"a": "b"}


@mock.patch.dict(os.environ, {}, clear=True)
def test_load_dotenv_only_bare_keys(dotenv_path):
dotenv_path.write_text("FOO\n")

result = dotenv.load_dotenv(dotenv_path)

assert result is False
assert os.environ == {}


@pytest.mark.parametrize(
"flag_value",
[
Expand Down
Loading