From 5ac574bd17808be8385be5693edd9efdf4a29913 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 6 Jul 2021 11:29:42 -0400 Subject: [PATCH] Tests: Fix failing expand_path() tests --- .../unit_tests/common/utils/test_common_file_utils.py | 8 ++++---- monkey/tests/unit_tests/conftest.py | 8 ++++++++ monkey/tests/unit_tests/monkey_island/conftest.py | 7 ------- 3 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 monkey/tests/unit_tests/conftest.py diff --git a/monkey/tests/unit_tests/common/utils/test_common_file_utils.py b/monkey/tests/unit_tests/common/utils/test_common_file_utils.py index b0f7c5862..226a403b8 100644 --- a/monkey/tests/unit_tests/common/utils/test_common_file_utils.py +++ b/monkey/tests/unit_tests/common/utils/test_common_file_utils.py @@ -3,15 +3,15 @@ import os from common.utils.file_utils import expand_path -def test_expand_user(mock_home_env): +def test_expand_user(patched_home_env): input_path = os.path.join("~", "test") - expected_path = os.path.join(mock_home_env, "test") + expected_path = os.path.join(patched_home_env, "test") assert expand_path(input_path) == expected_path -def test_expand_vars(mock_home_env): +def test_expand_vars(patched_home_env): input_path = os.path.join("$HOME", "test") - expected_path = os.path.join(mock_home_env, "test") + expected_path = os.path.join(patched_home_env, "test") assert expand_path(input_path) == expected_path diff --git a/monkey/tests/unit_tests/conftest.py b/monkey/tests/unit_tests/conftest.py new file mode 100644 index 000000000..a779d65fd --- /dev/null +++ b/monkey/tests/unit_tests/conftest.py @@ -0,0 +1,8 @@ +import pytest + + +@pytest.fixture +def patched_home_env(monkeypatch, tmpdir): + monkeypatch.setenv("HOME", str(tmpdir)) + + return tmpdir diff --git a/monkey/tests/unit_tests/monkey_island/conftest.py b/monkey/tests/unit_tests/monkey_island/conftest.py index 538576aef..2ccecd616 100644 --- a/monkey/tests/unit_tests/monkey_island/conftest.py +++ b/monkey/tests/unit_tests/monkey_island/conftest.py @@ -9,13 +9,6 @@ def server_configs_dir(data_for_tests_dir): return os.path.join(data_for_tests_dir, "server_configs") -@pytest.fixture -def patched_home_env(monkeypatch, tmpdir): - monkeypatch.setenv("HOME", str(tmpdir)) - - return tmpdir - - @pytest.fixture def create_empty_tmp_file(tmpdir: str) -> Callable: def inner(file_name: str):