diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_file_utils.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_file_utils.py index 79409ba7a..e9dc3eddc 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_file_utils.py +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_file_utils.py @@ -20,7 +20,7 @@ def test_expand_vars(patched_home_env): @pytest.mark.skipif(os.name != "posix", reason="Tests Posix (not Windows) permissions.") -def test_has_expected_permissions_true(tmpdir): +def test_has_expected_permissions_true(tmpdir, create_empty_file): file_name = f"{tmpdir}/test" create_empty_file(file_name) @@ -30,15 +30,10 @@ def test_has_expected_permissions_true(tmpdir): @pytest.mark.skipif(os.name != "posix", reason="Tests Posix (not Windows) permissions.") -def test_has_expected_permissions_false(tmpdir): +def test_has_expected_permissions_false(tmpdir, create_empty_file): file_name = f"{tmpdir}/test" create_empty_file(file_name) os.chmod(file_name, 0o755) assert not file_utils.has_expected_permissions(file_name, 0o700) - - -def create_empty_file(file_name): - with open(file_name, "w"): - pass diff --git a/monkey/tests/unit_tests/monkey_island/conftest.py b/monkey/tests/unit_tests/monkey_island/conftest.py index f45eb3ed6..2baa97a02 100644 --- a/monkey/tests/unit_tests/monkey_island/conftest.py +++ b/monkey/tests/unit_tests/monkey_island/conftest.py @@ -13,3 +13,12 @@ def patched_home_env(monkeypatch, tmpdir): monkeypatch.setenv("HOME", str(tmpdir)) return tmpdir + + +@pytest.fixture +def create_empty_file(): + def inner(file_name): + with open(file_name, "w"): + pass + + return inner