Skip to content

Commit 9915a25

Browse files
authored
fix(consume): fix consume cache's --cache-folder flag (#1851)
1 parent 5d02253 commit 9915a25

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Users can select any of the artifacts depending on their testing needs for their
4646

4747
#### `consume`
4848

49+
- 🐞 Fix `consume cache --cache-folder` parameter being ignored, now properly caches fixtures in the specified directory instead of always using the default system cache location.
4950
- 🔀 `consume` now automatically avoids GitHub API calls when using direct release URLs (better for CI environments), while release specifiers like `stable@latest` continue to use the API for version resolution ([#1788](https://github.com/ethereum/execution-spec-tests/pull/1788)).
5051
- 🔀 Refactor consume simulator architecture to use explicit pytest plugin structure with forward-looking architecture ([#1801](https://github.com/ethereum/execution-spec-tests/pull/1801)).
5152
- 🔀 Add exponential retry logic to initial fcu within consume engine ([#1815](https://github.com/ethereum/execution-spec-tests/pull/1815)).

src/pytest_plugins/consume/consume.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dataclasses import dataclass
77
from io import BytesIO
88
from pathlib import Path
9-
from typing import List, Tuple
9+
from typing import List, Optional, Tuple
1010
from urllib.parse import urlparse
1111

1212
import platformdirs
@@ -114,22 +114,28 @@ class FixturesSource:
114114
was_cached: bool = False
115115

116116
@classmethod
117-
def from_input(cls, input_source: str) -> "FixturesSource":
117+
def from_input(
118+
cls, input_source: str, cache_folder: Optional[Path] = None
119+
) -> "FixturesSource":
118120
"""Determine the fixture source type and return an instance."""
121+
if cache_folder is None:
122+
cache_folder = CACHED_DOWNLOADS_DIRECTORY
119123
if input_source == "stdin":
120124
return cls(input_option=input_source, path=Path(), is_local=False, is_stdin=True)
121125
if is_release_url(input_source):
122-
return cls.from_release_url(input_source)
126+
return cls.from_release_url(input_source, cache_folder)
123127
if is_url(input_source):
124-
return cls.from_url(input_source)
128+
return cls.from_url(input_source, cache_folder)
125129
if ReleaseTag.is_release_string(input_source):
126-
return cls.from_release_spec(input_source)
130+
return cls.from_release_spec(input_source, cache_folder)
127131
return cls.validate_local_path(Path(input_source))
128132

129133
@classmethod
130-
def from_release_url(cls, url: str) -> "FixturesSource":
134+
def from_release_url(cls, url: str, cache_folder: Optional[Path] = None) -> "FixturesSource":
131135
"""Create a fixture source from a supported github repo release URL."""
132-
downloader = FixtureDownloader(url, CACHED_DOWNLOADS_DIRECTORY)
136+
if cache_folder is None:
137+
cache_folder = CACHED_DOWNLOADS_DIRECTORY
138+
downloader = FixtureDownloader(url, cache_folder)
133139
was_cached, path = downloader.download_and_extract()
134140

135141
return cls(
@@ -142,9 +148,11 @@ def from_release_url(cls, url: str) -> "FixturesSource":
142148
)
143149

144150
@classmethod
145-
def from_url(cls, url: str) -> "FixturesSource":
151+
def from_url(cls, url: str, cache_folder: Optional[Path] = None) -> "FixturesSource":
146152
"""Create a fixture source from a direct URL."""
147-
downloader = FixtureDownloader(url, CACHED_DOWNLOADS_DIRECTORY)
153+
if cache_folder is None:
154+
cache_folder = CACHED_DOWNLOADS_DIRECTORY
155+
downloader = FixtureDownloader(url, cache_folder)
148156
was_cached, path = downloader.download_and_extract()
149157
return cls(
150158
input_option=url,
@@ -156,11 +164,13 @@ def from_url(cls, url: str) -> "FixturesSource":
156164
)
157165

158166
@classmethod
159-
def from_release_spec(cls, spec: str) -> "FixturesSource":
167+
def from_release_spec(cls, spec: str, cache_folder: Optional[Path] = None) -> "FixturesSource":
160168
"""Create a fixture source from a release spec (e.g., develop@latest)."""
169+
if cache_folder is None:
170+
cache_folder = CACHED_DOWNLOADS_DIRECTORY
161171
url = get_release_url(spec)
162172
release_page = get_release_page_url(url)
163-
downloader = FixtureDownloader(url, CACHED_DOWNLOADS_DIRECTORY)
173+
downloader = FixtureDownloader(url, cache_folder)
164174
was_cached, path = downloader.download_and_extract()
165175
return cls(
166176
input_option=spec,
@@ -307,7 +317,9 @@ def pytest_configure(config): # noqa: D103
307317
# NOTE: Setting `type=FixturesSource.from_input` in pytest_addoption() causes the option to
308318
# be evaluated twice which breaks the result of `was_cached`; the work-around is to call it
309319
# manually here.
310-
config.fixtures_source = FixturesSource.from_input(config.option.fixtures_source)
320+
config.fixtures_source = FixturesSource.from_input(
321+
config.option.fixtures_source, Path(config.option.fixture_cache_folder)
322+
)
311323
config.fixture_source_flags = ["--input", config.fixtures_source.input_option]
312324

313325
if "cache" in sys.argv and not config.fixtures_source:

src/pytest_plugins/consume/tests/test_fixtures_source_input_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from unittest.mock import MagicMock, patch
55

6-
from pytest_plugins.consume.consume import FixturesSource
6+
from pytest_plugins.consume.consume import CACHED_DOWNLOADS_DIRECTORY, FixturesSource
77

88

99
class TestSimplifiedConsumeBehavior:
@@ -141,7 +141,7 @@ def test_from_input_handles_release_url(self):
141141

142142
FixturesSource.from_input(test_url)
143143

144-
mock_from_release_url.assert_called_once_with(test_url)
144+
mock_from_release_url.assert_called_once_with(test_url, CACHED_DOWNLOADS_DIRECTORY)
145145

146146
def test_from_input_handles_release_spec(self):
147147
"""Test that from_input properly handles release specs."""
@@ -152,7 +152,7 @@ def test_from_input_handles_release_spec(self):
152152

153153
FixturesSource.from_input(test_spec)
154154

155-
mock_from_release_spec.assert_called_once_with(test_spec)
155+
mock_from_release_spec.assert_called_once_with(test_spec, CACHED_DOWNLOADS_DIRECTORY)
156156

157157
def test_from_input_handles_regular_url(self):
158158
"""Test that from_input properly handles regular URLs."""
@@ -163,4 +163,4 @@ def test_from_input_handles_regular_url(self):
163163

164164
FixturesSource.from_input(test_url)
165165

166-
mock_from_url.assert_called_once_with(test_url)
166+
mock_from_url.assert_called_once_with(test_url, CACHED_DOWNLOADS_DIRECTORY)

0 commit comments

Comments
 (0)