Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return False when we do not discover any environment variables #388

Merged
merged 4 commits into from Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 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 Expand Up @@ -324,6 +327,9 @@ def load_dotenv(
override: Whether to override the system environment variables with the variables
from the `.env` file.
encoding: Encoding to be used to read the file.

theskumar marked this conversation as resolved.
Show resolved Hide resolved
Returns:
Bool: True if atleast one environment variable is set elese False

If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
.env file.
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