Skip to content

Commit c2af53c

Browse files
vdusekclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 0e7fead commit c2af53c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

tests/unit/actor/test_actor_env_helpers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from apify import Actor
2323

2424
if TYPE_CHECKING:
25+
from pathlib import Path
26+
2527
import pytest
2628

2729

@@ -31,11 +33,12 @@ async def test_actor_is_not_at_home_when_local() -> None:
3133
assert is_at_home is False
3234

3335

34-
async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch) -> None:
36+
async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
3537
ignored_env_vars = {
3638
ApifyEnvVars.SDK_LATEST_VERSION,
3739
ApifyEnvVars.LOG_FORMAT,
3840
ApifyEnvVars.LOG_LEVEL,
41+
ApifyEnvVars.LOCAL_STORAGE_DIR,
3942
ActorEnvVars.STANDBY_PORT,
4043
ApifyEnvVars.PERSIST_STORAGE,
4144
}
@@ -127,6 +130,10 @@ async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch)
127130
expected_get_env[ApifyEnvVars.DEDICATED_CPUS.name.lower()]
128131
)
129132

133+
# LOCAL_STORAGE_DIR is excluded from randomization to avoid creating directories in the project root.
134+
# Its value is set by the _isolate_test_environment fixture to tmp_path.
135+
expected_get_env[ApifyEnvVars.LOCAL_STORAGE_DIR.name.lower()] = str(tmp_path)
136+
130137
await Actor.init()
131138
assert Actor.get_env() == expected_get_env
132139

0 commit comments

Comments
 (0)