import os from tests.file_handler import create_file, remove_file def test_create_file(): """ Function to test make file """ create_file(filename="delete_me.txt") assert os.path.isfile("delete_me.txt") def test_remove_file_with_mock(mocker): """ Test the removal of a file using mocking to avoid actual file system operations. """ filename = "delete_me.txt" # Mock os.remove to test file deletion without deleting anything mock_remove = mocker.patch("os.remove") # Mock os.path.isfile to control its return value mocker.patch("os.path.isfile", return_value=False) # Mock open for the create_file function mocker.patch("builtins.open", mocker.mock_open()) # Simulate file creation and removal create_file(filename) remove_file(filename) # Assert that os.remove was called correctly mock_remove.assert_called_once_with(filename) # Assert that os.path.isfile returns False, simulating that the file does not exist assert not os.path.isfile(filename)