From 301284f4d08d507646274e559a0b3da5399ef931 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Wed, 30 Mar 2022 17:58:13 +0300 Subject: [PATCH] UT: Fix windows bug in test_monkey_log_path.py Bug was happening due to an attempt to delete a file with an unclosed handle --- monkey/infection_monkey/utils/monkey_log_path.py | 4 +++- .../unit_tests/infection_monkey/utils/test_monkey_log_path.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/monkey/infection_monkey/utils/monkey_log_path.py b/monkey/infection_monkey/utils/monkey_log_path.py index b6daa714a..5fdc0b72b 100644 --- a/monkey/infection_monkey/utils/monkey_log_path.py +++ b/monkey/infection_monkey/utils/monkey_log_path.py @@ -1,3 +1,4 @@ +import os import tempfile import time from functools import lru_cache, partial @@ -11,7 +12,8 @@ def _get_log_path(monkey_arg: str) -> Path: prefix = f"infection-monkey-{monkey_arg}-{timestamp}-" suffix = ".log" - _, monkey_log_path = tempfile.mkstemp(suffix=suffix, prefix=prefix) + handle, monkey_log_path = tempfile.mkstemp(suffix=suffix, prefix=prefix) + os.close(handle) return Path(monkey_log_path) diff --git a/monkey/tests/unit_tests/infection_monkey/utils/test_monkey_log_path.py b/monkey/tests/unit_tests/infection_monkey/utils/test_monkey_log_path.py index 339b0f37a..eb67610ef 100644 --- a/monkey/tests/unit_tests/infection_monkey/utils/test_monkey_log_path.py +++ b/monkey/tests/unit_tests/infection_monkey/utils/test_monkey_log_path.py @@ -2,6 +2,7 @@ import pytest from infection_monkey.utils.monkey_log_path import get_agent_log_path, get_dropper_log_path + def delete_log_file(log_path): if log_path.is_file(): log_path.unlink()