diff --git a/tests/test_constants.py b/tests/test_constants.py index d760e653..b45cbabb 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -6,6 +6,7 @@ def test_default_user_home_cache_path_falls_back_to_temp_if_home_is_root(monkeypatch): + monkeypatch.setattr("os.getenv", lambda _variable: None) monkeypatch.setattr("os.path.expanduser", lambda _path: "/") cache_path = get_default_user_home_cache_path() @@ -14,6 +15,7 @@ def test_default_user_home_cache_path_falls_back_to_temp_if_home_is_root(monkeyp def test_default_user_home_cache_path_falls_back_to_temp_if_home_is_unresolved(monkeypatch): + monkeypatch.setattr("os.getenv", lambda _variable: None) monkeypatch.setattr("os.path.expanduser", lambda _path: "~") cache_path = get_default_user_home_cache_path() @@ -21,6 +23,14 @@ def test_default_user_home_cache_path_falls_back_to_temp_if_home_is_unresolved(m assert cache_path == os.path.join(tempfile.gettempdir(), ROOT_FOLDER_NAME) +def test_default_user_home_cache_path_with_xdg_cache_home_set(monkeypatch): + monkeypatch.setattr("os.getenv", lambda _variable: "/home/user/.cache") + + cache_path = get_default_user_home_cache_path() + + assert cache_path == os.path.join("/home/user/.cache", ROOT_FOLDER_NAME[1:]) + + def test_default_project_root_cache_path_uses_cwd_for_frozen_app(monkeypatch): monkeypatch.setattr("sys.path", ["C:/app/base_library.zip"]) monkeypatch.setattr("sys.frozen", True, raising=False) diff --git a/webdriver_manager/core/constants.py b/webdriver_manager/core/constants.py index aae5cfe5..56db31e4 100644 --- a/webdriver_manager/core/constants.py +++ b/webdriver_manager/core/constants.py @@ -16,6 +16,10 @@ def get_default_project_root_cache_path(): def get_default_user_home_cache_path(): + home = os.getenv('XDG_CACHE_HOME') + if home is not None: + return os.path.join(home, ROOT_FOLDER_NAME[1:]) + home = os.path.expanduser("~") if not home or home in (os.path.sep, "/") or home.startswith("~"): home = tempfile.gettempdir()