Skip to content

Commit

Permalink
Fix file not found message to have some context (#245)
Browse files Browse the repository at this point in the history
'File doesn't exist' doesn't really tell the user much, let's add some context.
  • Loading branch information
snobu committed Apr 29, 2020
1 parent 335dedc commit e92ab1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/dotenv/main.py
Expand Up @@ -74,7 +74,7 @@ def _get_stream(self):
yield stream
else:
if self.verbose:
logger.warning("File doesn't exist %s", self.dotenv_path)
logger.info("Python-dotenv could not find configuration file %s.", self.dotenv_path or '.env')
yield StringIO('')

def dict(self):
Expand Down
15 changes: 10 additions & 5 deletions tests/test_main.py
Expand Up @@ -74,14 +74,19 @@ def test_get_key_no_file(tmp_path):
nx_file = str(tmp_path / "nx")
logger = logging.getLogger("dotenv.main")

with mock.patch.object(logger, "warning") as mock_warning:
with mock.patch.object(logger, "info") as mock_info, \
mock.patch.object(logger, "warning") as mock_warning:
result = dotenv.get_key(nx_file, "foo")

assert result is None
mock_info.assert_has_calls(
calls=[
mock.call("Python-dotenv could not find configuration file %s.", nx_file)
],
)
mock_warning.assert_has_calls(
calls=[
mock.call("File doesn't exist %s", nx_file),
mock.call("Key %s not found in %s.", "foo", nx_file),
mock.call("Key %s not found in %s.", "foo", nx_file)
],
)

Expand Down Expand Up @@ -228,10 +233,10 @@ def test_load_dotenv_existing_file(dotenv_file):
def test_load_dotenv_no_file_verbose():
logger = logging.getLogger("dotenv.main")

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

mock_warning.assert_called_once_with("File doesn't exist %s", ".does_not_exist")
mock_info.assert_called_once_with("Python-dotenv could not find configuration file %s.", ".does_not_exist")


@mock.patch.dict(os.environ, {"a": "c"}, clear=True)
Expand Down

0 comments on commit e92ab1f

Please sign in to comment.