Skip to content

Commit cf36cc2

Browse files
vdusekclaude
andauthored
test: prevent storage directory leak from randomized env vars test (#779)
## Summary - `test_get_env_with_randomized_env_vars` was overriding `APIFY_LOCAL_STORAGE_DIR` with a random 10-char string (e.g. `KAHL8QER2W`), causing `Actor.init()` to create a leftover storage directory in the project root on every test run - Excluded `LOCAL_STORAGE_DIR` from randomization and set the expected value to the `tmp_path` provided by the `_isolate_test_environment` fixture ## Test plan - [x] `uv run poe lint` passes - [x] `uv run poe unit-tests` passes (249 tests) - [x] No leftover directories created in the project root after test run 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0e7fead commit cf36cc2

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)