File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ def _get_stream(self) -> Iterator[IO[str]]:
7474
7575 def dict (self ) -> Dict [str , Optional [str ]]:
7676 """Return dotenv as dict"""
77- if self ._dict :
77+ if self ._dict is not None :
7878 return self ._dict
7979
8080 raw_values = self .parse ()
Original file line number Diff line number Diff line change 1010import pytest
1111
1212import dotenv
13+ from dotenv .main import DotEnv
1314
1415
1516def test_set_key_no_file (tmp_path ):
@@ -227,6 +228,18 @@ def test_get_key_none(dotenv_path):
227228 mock_warning .assert_not_called ()
228229
229230
231+ def test_empty_dotenv_dict_is_cached (tmp_path ):
232+ dotenv_path = tmp_path / ".env"
233+ dotenv_path .write_text ("" )
234+ dotenv_obj = DotEnv (dotenv_path )
235+
236+ with mock .patch .object (dotenv_obj , "parse" , wraps = dotenv_obj .parse ) as mock_parse :
237+ assert dotenv_obj .dict () == {}
238+ assert dotenv_obj .dict () == {}
239+
240+ assert mock_parse .call_count == 1
241+
242+
230243def test_unset_with_value (dotenv_path ):
231244 logger = logging .getLogger ("dotenv.main" )
232245 dotenv_path .write_text ("a=b\n c=d" )
You can’t perform that action at this time.
0 commit comments