Skip to content

Commit f73324d

Browse files
committed
add pytest env to cache name to enforce unique cache per test file
1 parent 5f465c5 commit f73324d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

airbyte_cdk/sources/streams/http/http_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ def cache_filename(self) -> str:
127127
Override if needed. Return the name of cache file
128128
Note that if the environment variable REQUEST_CACHE_PATH is not set, the cache will be in-memory only.
129129
"""
130+
# This is a hack so that we ensure that the same cache is not used across different test files
131+
# because we observed some flakiness in tests when running on CI
132+
# https://github.com/airbytehq/airbyte-python-cdk/pull/688
133+
# https://github.com/airbytehq/airbyte-python-cdk/pull/712
134+
if os.getenv("PYTEST_CURRENT_TEST"):
135+
return f"{self._name}-{os.getenv('PYTEST_CURRENT_TEST')}.sqlite"
130136
return f"{self._name}.sqlite"
131137

132138
def _request_session(self) -> requests.Session:
@@ -153,7 +159,10 @@ def _request_session(self) -> requests.Session:
153159
# * `If the application running SQLite crashes, the data will be safe, but the database [might become corrupted](https://www.sqlite.org/howtocorrupt.html#cfgerr) if the operating system crashes or the computer loses power before that data has been written to the disk surface.` in [this description](https://www.sqlite.org/pragma.html#pragma_synchronous).
154160
backend = requests_cache.SQLiteCache(sqlite_path, fast_save=True, wal=True)
155161
return CachedLimiterSession(
156-
sqlite_path, backend=backend, api_budget=self._api_budget, match_headers=True
162+
cache_name=sqlite_path,
163+
backend=backend,
164+
api_budget=self._api_budget,
165+
match_headers=True,
157166
)
158167
else:
159168
return LimiterSession(api_budget=self._api_budget)

0 commit comments

Comments
 (0)