Skip to content

Commit f1ce95c

Browse files
use separate tmpdir for CRL cache in tests
1 parent bd45036 commit f1ce95c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/unit/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,32 @@ def fake_github_actions_metadata_service():
9898
"""Emulates the GitHub Actions metadata service."""
9999
with FakeGitHubActionsService() as server:
100100
yield server
101+
102+
103+
@pytest.fixture(autouse=True)
104+
def crl_cache_tmpdir(request, tmp_path, monkeypatch):
105+
"""
106+
Fixture that patches the CRL cache directory to use a temporary directory.
107+
108+
This prevents tests from creating the cache folder in the real system location
109+
(e.g., ~/Library/Caches/Snowflake/crls on macOS) and ensures test isolation.
110+
"""
111+
# Exclude test checking default cache path
112+
if "test_platform_specific_cache_path" in request.node.name:
113+
return None
114+
115+
from snowflake.connector import crl_cache
116+
117+
# Create a temporary cache directory for this test
118+
temp_crl_cache = tmp_path / "crl_cache"
119+
temp_crl_cache.mkdir(mode=0o700)
120+
121+
# Patch the function that returns the default cache path
122+
monkeypatch.setattr(
123+
crl_cache, "_get_default_crl_cache_path", lambda: temp_crl_cache
124+
)
125+
126+
# Also reset the file cache singleton to ensure each test gets a fresh cache
127+
monkeypatch.setattr(crl_cache.CRLCacheFactory, "_file_cache_instance", None)
128+
129+
return temp_crl_cache

0 commit comments

Comments
 (0)