@@ -642,65 +642,4 @@ def test_unlink_after_load_with_empty_file(self, tmp_path):
642642 assert result is False
643643
644644 # Verify file was still removed even though no variables were loaded
645- assert not dotenv_file .exists ()
646-
647- def test_unlink_after_load_with_verbose_logging (self , tmp_path , caplog ):
648- """Test that verbose logging shows unlink operation."""
649- dotenv_file = tmp_path / ".env"
650- dotenv_file .write_text ("TEST_VAR5=test_value5\n " )
651-
652- with caplog .at_level (logging .INFO ):
653- result = dotenv .load_dotenv (
654- dotenv_path = str (dotenv_file ),
655- unlink_after_load = True ,
656- verbose = True
657- )
658-
659- # Verify loading was successful
660- assert result is True
661- assert os .environ .get ("TEST_VAR5" ) == "test_value5"
662-
663- # Verify file was removed
664- assert not dotenv_file .exists ()
665-
666- # Verify log message about removal
667- assert any ("Removed dotenv file" in record .message for record in caplog .records )
668-
669- # Clean up environment
670- if "TEST_VAR5" in os .environ :
671- del os .environ ["TEST_VAR5" ]
672-
673- def test_unlink_after_load_permission_error (self , tmp_path , caplog , monkeypatch ):
674- """Test handling of permission errors when unlinking."""
675- dotenv_file = tmp_path / ".env"
676- dotenv_file .write_text ("TEST_VAR6=test_value6\n " )
677-
678- # Mock os.unlink to raise a permission error
679- original_unlink = os .unlink
680- def mock_unlink (path ):
681- if str (dotenv_file ) in str (path ):
682- raise PermissionError ("Permission denied" )
683- return original_unlink (path )
684-
685- monkeypatch .setattr (os , "unlink" , mock_unlink )
686-
687- with caplog .at_level (logging .WARNING ):
688- result = dotenv .load_dotenv (
689- dotenv_path = str (dotenv_file ),
690- unlink_after_load = True ,
691- verbose = True
692- )
693-
694- # Verify loading was successful despite unlink failure
695- assert result is True
696- assert os .environ .get ("TEST_VAR6" ) == "test_value6"
697-
698- # Verify file still exists due to permission error
699- assert dotenv_file .exists ()
700-
701- # Verify warning log message about failed removal
702- assert any ("Failed to remove dotenv file" in record .message for record in caplog .records )
703-
704- # Clean up environment
705- if "TEST_VAR6" in os .environ :
706- del os .environ ["TEST_VAR6" ]
645+ assert not dotenv_file .exists ()
0 commit comments