Skip to content

Commit bb3516e

Browse files
address review feedback: add docstrings, fix env cleanup in tests
1 parent 002bfb6 commit bb3516e

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/dotenv/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

tests/test_on_duplicate.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import os
32
from unittest.mock import patch
43

54
import 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\nMYKEY=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\nMYKEY=second\n")

0 commit comments

Comments
 (0)