File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -427,6 +427,8 @@ def load_dotenv(
427427 from the `.env` file.
428428 interpolate: Whether to interpolate variables using POSIX variable expansion.
429429 encoding: Encoding to be used to read the file.
430+ on_duplicate: How to handle duplicate keys. "warn" logs a warning,
431+ "raise" raises a ValueError, "ignore" silently uses the latter value.
430432 Returns:
431433 Bool: True if at least one environment variable is set else False
432434
Original file line number Diff line number Diff line change 11import logging
2- import os
32from unittest .mock import patch
43
54import pytest
@@ -40,13 +39,13 @@ def test_invalid_option_raises(self, tmp_path):
4039 with pytest .raises (ValueError , match = "Invalid value for on_duplicate" ):
4140 DotEnv (env_file , on_duplicate = "bad-value" )
4241
43- def test_load_dotenv_warn (self , tmp_path ):
42+ def test_load_dotenv_warn (self , tmp_path , monkeypatch ):
4443 env_file = _write_env (tmp_path , "MYKEY=first\n MYKEY=second\n " )
44+ monkeypatch .delenv ("MYKEY" , raising = False )
4545 with patch .object (logging .getLogger ("dotenv.main" ), "warning" ) as mock_warn :
4646 dotenv .load_dotenv (env_file , override = True , on_duplicate = "warn" )
4747 assert mock_warn .called
4848 assert "Duplicate key" in mock_warn .call_args [0 ][0 ]
49- del os .environ ["MYKEY" ]
5049
5150 def test_load_dotenv_raise (self , tmp_path ):
5251 env_file = _write_env (tmp_path , "MYKEY=first\n MYKEY=second\n " )
You can’t perform that action at this time.
0 commit comments