Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
removed caplog tests
  • Loading branch information
sha1cybr committed Oct 19, 2025
commit f9ebd8e244816e428067227a95533755552faeb8
63 changes: 1 addition & 62 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,65 +642,4 @@ def test_unlink_after_load_with_empty_file(self, tmp_path):
assert result is False

# Verify file was still removed even though no variables were loaded
assert not dotenv_file.exists()

def test_unlink_after_load_with_verbose_logging(self, tmp_path, caplog):
"""Test that verbose logging shows unlink operation."""
dotenv_file = tmp_path / ".env"
dotenv_file.write_text("TEST_VAR5=test_value5\n")

with caplog.at_level(logging.INFO):
result = dotenv.load_dotenv(
dotenv_path=str(dotenv_file),
unlink_after_load=True,
verbose=True
)

# Verify loading was successful
assert result is True
assert os.environ.get("TEST_VAR5") == "test_value5"

# Verify file was removed
assert not dotenv_file.exists()

# Verify log message about removal
assert any("Removed dotenv file" in record.message for record in caplog.records)

# Clean up environment
if "TEST_VAR5" in os.environ:
del os.environ["TEST_VAR5"]

def test_unlink_after_load_permission_error(self, tmp_path, caplog, monkeypatch):
"""Test handling of permission errors when unlinking."""
dotenv_file = tmp_path / ".env"
dotenv_file.write_text("TEST_VAR6=test_value6\n")

# Mock os.unlink to raise a permission error
original_unlink = os.unlink
def mock_unlink(path):
if str(dotenv_file) in str(path):
raise PermissionError("Permission denied")
return original_unlink(path)

monkeypatch.setattr(os, "unlink", mock_unlink)

with caplog.at_level(logging.WARNING):
result = dotenv.load_dotenv(
dotenv_path=str(dotenv_file),
unlink_after_load=True,
verbose=True
)

# Verify loading was successful despite unlink failure
assert result is True
assert os.environ.get("TEST_VAR6") == "test_value6"

# Verify file still exists due to permission error
assert dotenv_file.exists()

# Verify warning log message about failed removal
assert any("Failed to remove dotenv file" in record.message for record in caplog.records)

# Clean up environment
if "TEST_VAR6" in os.environ:
del os.environ["TEST_VAR6"]
assert not dotenv_file.exists()