From c2af53ca0d6255f3bbf8d7c05c528fb0c3fd1fbf Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Wed, 11 Feb 2026 12:41:28 +0100 Subject: [PATCH] test: prevent storage directory leak from randomized env vars test The test_get_env_with_randomized_env_vars test was overriding APIFY_LOCAL_STORAGE_DIR with a random 10-char string, causing Actor.init() to create a storage directory in the project root. Exclude LOCAL_STORAGE_DIR from randomization and use the tmp_path value set by the _isolate_test_environment fixture instead. Co-Authored-By: Claude Opus 4.6 --- tests/unit/actor/test_actor_env_helpers.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/unit/actor/test_actor_env_helpers.py b/tests/unit/actor/test_actor_env_helpers.py index 3d78f94e..25e337bb 100644 --- a/tests/unit/actor/test_actor_env_helpers.py +++ b/tests/unit/actor/test_actor_env_helpers.py @@ -22,6 +22,8 @@ from apify import Actor if TYPE_CHECKING: + from pathlib import Path + import pytest @@ -31,11 +33,12 @@ async def test_actor_is_not_at_home_when_local() -> None: assert is_at_home is False -async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch) -> None: +async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: ignored_env_vars = { ApifyEnvVars.SDK_LATEST_VERSION, ApifyEnvVars.LOG_FORMAT, ApifyEnvVars.LOG_LEVEL, + ApifyEnvVars.LOCAL_STORAGE_DIR, ActorEnvVars.STANDBY_PORT, ApifyEnvVars.PERSIST_STORAGE, } @@ -127,6 +130,10 @@ async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch) expected_get_env[ApifyEnvVars.DEDICATED_CPUS.name.lower()] ) + # LOCAL_STORAGE_DIR is excluded from randomization to avoid creating directories in the project root. + # Its value is set by the _isolate_test_environment fixture to tmp_path. + expected_get_env[ApifyEnvVars.LOCAL_STORAGE_DIR.name.lower()] = str(tmp_path) + await Actor.init() assert Actor.get_env() == expected_get_env