From 7915a6a2ec4a8fdf0dd8b5e2077d73a054f5d536 Mon Sep 17 00:00:00 2001 From: wwakabobik Date: Tue, 20 Aug 2024 21:39:31 +0200 Subject: [PATCH] Add test_reporter_utils_delete_file.py --- .../utils/test_reporter_utils_delete_file.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/utils/test_reporter_utils_delete_file.py diff --git a/tests/utils/test_reporter_utils_delete_file.py b/tests/utils/test_reporter_utils_delete_file.py new file mode 100644 index 0000000..0d24070 --- /dev/null +++ b/tests/utils/test_reporter_utils_delete_file.py @@ -0,0 +1,44 @@ +"""Tests for the reporter_utils module, function 'delete_file'""" + +import os +from unittest.mock import MagicMock + +from testrail_api_reporter.utils.reporter_utils import delete_file # pylint: disable=import-error,no-name-in-module + + +def test_delete_file(): + """Test delete file""" + test_file = "test_file.txt" + with open(test_file, "w") as file: + file.write("Test") + + assert os.path.exists(test_file) is True + delete_file(test_file, debug=False) + + assert os.path.exists(test_file) is False + + +def test_delete_file_with_debug(): + """Test delete file with debug output""" + test_file = "test_file.txt" + with open(test_file, "w") as file: + file.write("Test") + + assert os.path.exists(test_file) is True + mock_logger = MagicMock() + delete_file(test_file, debug=True, logger=mock_logger) + + assert os.path.exists(test_file) is False + mock_logger.debug.assert_called_once_with(f"Removed {test_file}") + + +def test_delete_file_non_existent(capfd): + """ + Test delete non-existing file + + :param capfd - fixture of cap failure logger + """ + delete_file("non_existent_file.txt", debug=True) + out, err = capfd.readouterr() + + assert "No such file or directory" in err