Skip to content

Commit fe14cd8

Browse files
patched os dictionary so that is clears it before every test and then additively adds environments for every fake environment
1 parent c082f40 commit fe14cd8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

test/csp_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def __enter__(self):
130130
side_effect=ConnectTimeout(),
131131
)
132132
)
133+
# Patch the environment variables to fake the metadata service
134+
# Note that this doesn't clear, so it's additive to the existing environment.
133135
self.patchers.append(patch.dict(os.environ, self.get_environment_variables()))
134136
for patcher in self.patchers:
135137
patcher.__enter__()

test/unit/test_detect_platforms.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from __future__ import annotations
22

3+
import os
4+
from unittest.mock import patch
5+
36
import pytest
47

58
from snowflake.connector.platform_detection import detect_platforms
@@ -14,10 +17,12 @@ def build_response(status_code=200, headers=None):
1417

1518

1619
class TestDetectPlatforms:
17-
# TODO: add this back probably once I verify caching is causing the test failures
18-
# @pytest.fixture(autouse=True)
19-
# def teardown(self):
20-
# yield
20+
@pytest.fixture(autouse=True)
21+
def teardown(self):
22+
with patch.dict(os.environ, clear=True):
23+
yield
24+
25+
# TODO: add this back probably once I verify caching is causing the test failures
2126
# detect_platforms.cache_clear() # clear cache after each test
2227

2328
def test_no_platforms_detected(self, broken_metadata_service):

0 commit comments

Comments
 (0)