Skip to content

Commit

Permalink
Return False when we do not discover any environment variables
Browse files Browse the repository at this point in the history
This modifies Dotenv.set_as_environment_variables to return False
if we have not discovered any environment variables via either
`dotenv_path` or `stream`.

The return value gets passed through to `load_dotenv`, so this can be
used to determine if `dotenv.load_dotenv` was able to set anything.

Closes #321
  • Loading branch information
larsks committed Mar 15, 2022
1 parent e139830 commit 1371bb8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/dotenv/main.py
Expand Up @@ -87,6 +87,9 @@ def set_as_environment_variables(self) -> bool:
"""
Load the current dotenv as system environment variable.
"""
if not self.dict():
return False

for k, v in self.dict().items():
if k in os.environ and not self.override:
continue
Expand Down
3 changes: 2 additions & 1 deletion tests/test_main.py
Expand Up @@ -259,8 +259,9 @@ def test_load_dotenv_no_file_verbose():
logger = logging.getLogger("dotenv.main")

with mock.patch.object(logger, "info") as mock_info:
dotenv.load_dotenv('.does_not_exist', verbose=True)
result = dotenv.load_dotenv('.does_not_exist', verbose=True)

assert result is False
mock_info.assert_called_once_with("Python-dotenv could not find configuration file %s.", ".does_not_exist")


Expand Down

0 comments on commit 1371bb8

Please sign in to comment.